howtothings.co.uk
Hello World - Your first Python program - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Programming Support, Graphic Design and Tutorials (https://www.howtothings.co.uk/forumdisplay.php?fid=14)
+--- Thread: Hello World - Your first Python program (/showthread.php?tid=247)



Hello World - Your first Python program - Mark - 13-07-2010

This is the first of many tutorials to come on how to program in Python, let's start it off simple with a hello world program.

The first line of a python script should always be "#!/usr/bin/env python" this is there because on Linux, python may be installed in different directorys, it'll figure out the correct location of python from $PATH and make that as the interpreter for rest of the script.

[code=python]
#!/usr/bin/env python
[/code]

The print command is pretty self explanatory, it simply means print or show the words "Hello World".

[code=python]
print "Hello world"
[/code]

The finished script, yes it's that easy.

[code=python]
#!/usr/bin/env python
print "Hello world"
[/code]

When running a python script in Linux you should use the following syntax. You need to state that the file is a python file first, and then enter the file you wish to run.

Code:
python script.py