Invalid syntax with print "Hello World"

Started by
2 comments, last by 0x3a 12 years, 7 months ago
obviously total mewbiew:

My first program in Python Windows

print "hello, world!"

I select Run/Run Module and get an error:

Syntax error, with the closing quote highlighted.

Tried with single quotes as well. Same problem.

Can someone explain my mistake?

Thanks,
Advertisement
Which version of Python are you using? That's valid Python 2.x code, but not valid Python 3.

Which version of Python are you using? That's valid Python 2.x code, but not valid Python 3.


I'm using python 2.4
Like SiCrane said that is valid Python 2.x code but not valid code for Python 3, in Python 3 you'd have to do
print("hello, world!")

Assuming you installed the latest version of python I think you are using python 2.x syntax in python 3 ;)

See this link for more information: http://docs.python.o...atsnew/3.0.html

The print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement (PEP 3105). Examples:
Old: print "The answer is", 2*2
New: print("The answer is", 2*2)

Old: print x, # Trailing comma suppresses newline
New: print(x, end=" ") # Appends a space instead of a newline

Old: print # Prints a newline
New: print() # You must call the function!

Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)

Old: print (x, y) # prints repr((x, y))
New: print((x, y)) # Not the same as print(x, y)!
[/quote]
If I've helped you in any way please push the reputation button, thanks!

Abstraction is my choice of words.
Portfolio: http://www.0x3a.com/
Blog: http://blog.0x3a.com/

This topic is closed to new replies.

Advertisement