howtothings.co.uk

Full Version: Hello World - Your first Python program
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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