Invalid syntax on hello world program

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

  1. ianb


    Mar 11, 2011
    Likes Received:
    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

    # Filename :
    print 'Hello World'

    then opened up a terminal and typed python 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. Advertisements

  2. ianb


    Jun 28, 2017
    Likes Received:
    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
    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.