Invalid syntax on hello world program

Discussion in 'Python' started by ianb, Mar 11, 2011.

  1. ianb

    ianb

    Joined:
    Mar 11, 2011
    Messages:
    1
    Likes Received:
    0
    Hi, i'm just starting to learn python obviously and trying to get this program to run and it comes back as invalid syntax.

    Python 2.6.

    Print 'hello world' works fine, but i wrote the following program in text wrangler

    #!/usr/bin/python
    # Filename : helloworld.py
    print 'Hello World'

    then opened up a terminal and typed python helloworld.py and it comes back as invalid syntax.

    I'm a right beginner at all this but i've tried numerous different ways of writing it with brackets, quotes, double quotes, spaces etc., and i cant' get anything to work... nor can i seem to find a definitive answer in my search on what python 2.6 syntax is.

    So basically i feel stuck with no being able to continue working through the guide until i can get this program working. Any help be great.
     
    ianb, Mar 11, 2011
    #1
    1. Advertisements

  2. ianb

    UoPTucson

    Joined:
    Jun 28, 2017
    Messages:
    5
    Likes Received:
    2
    There have been some definite changes between Python 2.x and Python 3.x.
    While you are in the Python 2.6 interpreter, your code works fine, but when you dropped into a terminal and
    started python, you got python 3.x

    so to be clear:
    Python 2.x:
    print 'Hello World'

    Python 3.x:
    print("Hello World")
    Note the () in the print function.
     
    UoPTucson, Jul 3, 2017
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.