• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hello World - Your first Python program
#1
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
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Graziano is selling python-forum.org Mark 1 10,992 17-10-2012, 11:55 PM
Last Post: Mark
  For those who have chosen Python as their primary.. latch 1 6,977 22-11-2010, 04:10 PM
Last Post: Mark
  Python programmer employability Pack3t SynAck3r 1 7,069 07-07-2010, 08:58 PM
Last Post: Mark
  (Batch) Hello world - Your first Batch program Mark 0 6,486 22-05-2010, 10:35 PM
Last Post: Mark

Forum Jump: