• 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
  What program(s) do you use?‏ Mark 16 47,409 31-01-2014, 12:03 PM
Last Post: ajeesh
  Graziano is selling python-forum.org Mark 1 11,829 17-10-2012, 11:55 PM
Last Post: Mark
  My first ever program. Lewis_ 5 17,176 16-11-2011, 04:02 AM
Last Post: latch
  Everyone in the world will die if I use the stack. latch 5 14,800 01-02-2011, 10:05 PM
Last Post: latch
  For those who have chosen Python as their primary.. latch 1 7,561 22-11-2010, 04:10 PM
Last Post: Mark

Forum Jump: