Thursday, May 5, 2011

python syntax error on print

I'm new to python and am currently lost as to why print is giving a syntax here. Hoping someone might be able to point me in the right direction. Thanks

Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello World"
  File "<stdin>", line 1
    print "hello World"
                      ^
SyntaxError: invalid syntax
>>> exit()

Windows path is correctly pointing to the python directory.

From stackoverflow
  • In Python 3.0, print became a function. You need to include parenthesis now.

    print("Hello World")
    

    http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

  • It looks like you're using Python 3.0, in which print has turned into a callable function rather than a statment.

    print('Hello world!')
    

    http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function

  • In Python 3.0, print is a regular function that requires ():

    print("Hello world")
    
  • It looks like you're using Python 3. In Python 3, print has been changed to a method instead of a statement. Try this:

    print("hello World")
    
  • In python 3, it's print("something") , not print "something"

0 comments:

Post a Comment