What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?

When I try to use a print statement in Python, it gives me this error:

>>> print "Hello, World!"
  File "<stdin>", line 1
    print "Hello, World!"
                        ^
SyntaxError: Missing parentheses in call to 'print'

What does that mean?

This error message means that you are attempting to use Python 3 to follow an example or run a program that uses the Python 2 print statement:

print "Hello, World!"

The statement above does not work in Python 3. In Python 3 you need to add parentheses around the value to be printed:

print("Hello, World!")

"SyntaxError: Missing parentheses in call to 'print'" is a new error message that was added in Python 3.4.2 primarily to help users that are trying to follow a Python 2 tutorial while running Python 3.

In Python 3, printing values changed from being a distinct statement to being an ordinary function call, so it now needs parentheses:

>>> print("Hello, World!")
Hello, World!

In earlier versions of Python 3, the interpreter just reports a generic syntax error, without providing any useful hints as to what might be going wrong:

>>> print "Hello, World!"
  File "<stdin>", line 1
    print "Hello, World!"
                        ^
SyntaxError: invalid syntax

As for why print became an ordinary function in Python 3, that didn't relate to the basic form of the statement, but rather to how you did more complicated things like printing multiple items to stderr with a trailing space rather than ending the line.

In Python 2:

>>> import sys
>>> print >> sys.stderr, 1, 2, 3,; print >> sys.stderr, 4, 5, 6
1 2 3 4 5 6

In Python 3:

>>> import sys
>>> print(1, 2, 3, file=sys.stderr, end=" "); print(4, 5, 6, file=sys.stderr)
1 2 3 4 5 6

Starting with the Python 3.6.3 release in September 2017, some error messages related to the Python 2.x print syntax have been updated to recommend their Python 3.x counterparts:

>>> print "Hello!"
  File "<stdin>", line 1
    print "Hello!"
                 ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello!")?

Since the "Missing parentheses in call to print" case is a compile time syntax error and hence has access to the raw source code, it's able to include the full text on the rest of the line in the suggested replacement. However, it doesn't currently try to work out the appropriate quotes to place around that expression (that's not impossible, just sufficiently complicated that it hasn't been done).

The TypeError raised for the right shift operator has also been customised:

>>> print >> sys.stderr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'. Did you mean "print(<message>, file=<output_stream>)"?

Since this error is raised when the code runs, rather than when it is compiled, it doesn't have access to the raw source code, and hence uses meta-variables (<message> and <output_stream>) in the suggested replacement expression instead of whatever the user actually typed. Unlike the syntax error case, it's straightforward to place quotes around the Python expression in the custom right shift error message.

What Does Covid-19 Do to Your Brain?, Even though a historic decline for oil sent prices negative on Monday, don't expect to get paid to fill up your gas tank any time soon. The :-) notation is known as a smiley, and means that the statement it follows was intended as humor. When you tilt your head to the side, you see that : is the eyes, - the optional nose, and ) is the mouth.

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

Since Python 3.0 you have to write:

print("Hello, World!")

And someone has still to write that antigravity library :(

The Fox (What Does the Fox Say?), Most mutations don't really change how the virus functions. Below is a glimpse at an imaginary virus. It's doing what all viruses do: entering a cell,  Define does. does synonyms, does pronunciation, does translation, English dictionary definition of does. v. Third person singular present tense of do1. vb a form of the present tense of do1 n taboo slang South African a foolish or despicable person n., pl.

There is a change in syntax from Python 2 to Python 3. In Python 2,

print "Hello, World!" 

will work but in Python 3, use parentheses as

print("Hello, World!")

This is equivalent syntax to Scala and near to Java.

What does it mean when oil prices go negative? No, it doesn't mean , The cappuccinos and hair colorist. The twice-a-week Pilates. The monthly facial. I don't need all of it. o.O = surprise, shock, yawn. Was this answer helpful? what does ;v; mean? my friend used it in a text but I have no idea what it means. Was this answer helpful? Was this answer helpful? Was this answer helpful? it is an excited smiley. like ^v^ but then he has the commas from the ; which add two hands holding his cheeks. its just some weird

If your code should work in both Python 2 and 3, you can achieve this by loading this at the beginning of your program:

from __future__ import print_function   # If code has to work in Python 2 and 3!

Then you can print in the Python 3 way:

print("python")

If you want to print something without creating a new line - you can do this:

for number in range(0, 10):
    print(number, end=', ')

Opinion, President Trump has been critical - but what do others think of the "global guardian of public health"? A radiologist is a doctor who interprets medical imaging, such as X-rays. Learn more about what they do and the education that they receive here.

In Python 3, you can only print as:

print("STRING")

But in Python 2, the parentheses are not necessary.

Opinion, What is furlough? Furlough supports firms hit by coronavirus by temporarily helping to pay the wages of people who can't do their jobs. It allows employees to​  :) is used in texting, and it is usually changed to something like: There are many different emojis used, in their letter format. :P is a tongue sticking out, :D is a huge grin, and :| is a sort of neutral face. Also note, you can see what it looks like by tilting your head and making the colons (:) at the top.

World Health Organization: What is the WHO and what does it do , Recovery involves biology, epidemiology and a little bit of bureaucracy too. How does your body fight off COVID-19? Once a person is exposed  What does your name really stand for? Get an adjective for each letter in your name.

Coronavirus: What does it mean if I've been furloughed by work , The Fox (What Does the Fox Say?) The Fox (What Does the Fox Say?) Licensed to YouTube by. WMG (on behalf of PLG Norway); CMRRA, SOLAR Music Rights Management, LatinAutor, BMI - Broadcast Music Inc

What does 'recovered from coronavirus' mean? 4 questions , It means exactly the same as on singularly. It’s an exclamation mark. It’s used to express and emphasis sudden noise, loud statments and speech to shouting and screaming in text. The amount of exclamation marks used at the end of a sentence can be used to show almost like the volume or suprise in the sentence.

Comments
  • My thanks to @antti-haapala for adding the summary at the top that directly answers the question before continuing on to the longer explanation of the origins of the error message :)
  • I also switched the answer to community wiki, as steadily accumulating further SO rep for this doesn't feel right to me (see bugs.python.org/issue21669 for the background on how the error message and this SO question co-evolved)
  • Hello! I think this tool can help someone docs.python.org/2/library/2to3.html
  • Add the line from future import print_function in your 2.7 file to add new python 3 print() lines to your code. Hence the code becomes compatible to 2.7+ and 3.0+
  • How do you force the system to use Python 2.7 vs 3? Perhaps this is a good place for it.
  • antigravity is there though ... have you tried importing it? ;)
  • AntiGravity Easter Egg