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?

Asked By: MiffTheFox

||

Answers:

print("Hello, World!")

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

Answered By: Unknown

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 🙁

Answered By: Christian

In python 3.x. you use

print("Hello, World")

In Python 2.x. you use

print "Hello, World!"
Answered By: Anish Gupta
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.