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,
Invalid syntax with print "Hello World"
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
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
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
[/quote]
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)!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement