Syntax error on print with Python 3


Question

Why do I receive a syntax error when printing a string in Python 3?

>>> print "hello World"
  File "<stdin>", line 1
    print "hello World"
                      ^
SyntaxError: invalid syntax
1
259
9/12/2014 7:20:57 AM

Accepted Answer

In Python 3, print became a function. This means that you need to include parenthesis now like mentioned below:

print("Hello World")
328
2/14/2017 7:24:58 AM

It looks like you're using Python 3.0, in which print has turned into a callable function rather than a statement.

print('Hello world!')

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