Jump to content
  • Advertisement
Sign in to follow this  
golden code

Invalid syntax with print "Hello World"

This topic is 2616 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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,

Share this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!