Hello World in Python


Question

I tried running a python script:

print "Hello, World!" 

And I get this error:

  File "hello.py", line 1
    print "Hello, World!"
                        ^
SyntaxError: invalid syntax

What is going on?

1
130
5/10/2014 8:59:50 PM

Accepted Answer

print("Hello, World!")

You are probably using Python 3.0, where print is now a function (hence the parenthesis) instead of a statement.

178
9/7/2012 6:19:22 AM

Unfortunately the xkcd comic isn't completely up to date anymore.

https://imgs.xkcd.com/comics/python.png

Since Python 3.0 you have to write:

print("Hello world!")

And someone still has to write that antigravity library :(


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon