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.
The Python error “SyntaxError: Missing parentheses in call to ‘print’ …” occurs when you use an old-style print statement (e.g., print 'some value'
) in Python 3.
This not so short error message looks like this:
File /dwd/sandbox/test.py, line 1
print 'some text here'
^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
As the error explains, from version 3, print()
is a function in Python and must be used as an ordinary function call:
# 🚫 This style of print statements only work in older versions of Python
print 'hello world'
# ✅ To fix the issue, we add parentheses
print('some text here')
You might get this error if you’re running an old code in Python 3 or have copied a code snippet from an old post on Stackoverflow.
How to fix it?
All you need to do is to call print()
with your string literal(s) as its argument(s) — and do the same to every old-style print statement in your code.
The print()
function is much more robust than its predecessor. Python 3 printing method enables you to adjust the print()
function’s behavior based on your requirements.
👇 Continue Reading
For instance, to print a list of values separated by a character (e.g., a space or comma), you can pass them as multiple arguments to the print()
function:
# ✅ Using print() with multiple arguments:
price = 49.99
print('The value is', price)
# output: The value is 49.99
As you can see, the arguments are separated by whitespace; You can change the delimiter via the sep
keyword argument:
print('banana', 'apple', 'orange', sep=', ')
# output: banana, apple, orange
Python 3 takes the dynamic text generation to a new level by providing formatted string literals (a.k.a f-strings) and the print()
function.
One of the benefits of f-strings is concatenating values of different types (e.g., integers and strings) without having to cast them to string values.
You create an f-string by prefixing it with f
or F
and writing expressions inside curly braces ({}
):
user = {
'name': 'John',
'score': 75
}
print(f'User: {user[name]}, Score: {user[score]}')
# output: User: John, Score: 75
In python 2.7, you’d have to use the +
operator or printf-style formatting.
Please note that f-strings were added to Python from version 3.6 and don’t work in Python’s older versions. For versions prior to 3.6, check out the str.format()
function.
Alright, I think it does it. I hope this quick guide helped you solve your problem.
Thanks for reading.
Reza Lavarian Hey 👋 I’m a software engineer, an author, and an open-source contributor. I enjoy helping people (including myself) decode the complex side of technology. I share my findings on Twitter: @rlavarian
In Python 3, you must enclose all print statements with parenthesis. If you try to print out a string to the console without enclosing the string in parenthesis, you’ll encounter the “SyntaxError: Missing parentheses in call to ‘print’” error.
This guide discusses what this error means and how to use the print statement in Python. We’ll walk through an example of this error so you can learn how to solve it.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
Select your interest
First name
Last name
Phone number
By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.
SyntaxError: Missing parentheses in call to ‘print’
Python 3 is the third major update to the programming language. In recent years, it has become the preferred version of Python to use.
Python 3 changed the way that print statements are written. The standalone print
statement works in Python 2 and prints a statement to the console.
In Python 3, print
is a function. This means you need to surround the contents of the string you want to print to the console in parenthesis like you do with any ordinary function call.
An Example Scenario
Write a program that prints out the names of all the students in a fourth grade class whose names begin with “A”. To start, define a list that contains the names of the students in the class:
students = ["Alex", "Alexander", "Piper", "Molly", "Hannah"]
Next, write a for loop that iterates over all the items in this list. In the for loop, we’ll use an if
statement to check if each name begins with “A”:
for s in students: if s.startswith("A") == True: print s
The startswith() method checks if a string starts with a particular character or set of characters. The code checks whether each name in the “students” list begins with “A”.
Add an extra print statement to the end of the code that tells us the program has finished running:
print "Above are all the students whose names begin with A."
Now you’re ready to run the program:
File "main.py", line 5 print s ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(s)?
The code informs us that there is a syntax error in the program.
The Solution
Handily, Python already offers the solution to the problem in the error message.
This is because, in previous versions of Python 3, forgetting to include parenthesis around a print statement raised an error which only showed “invalid syntax”. This message is ambiguous because invalid syntax can be caused by a number of issues. Thus, Python introduced the new “missing parenthesis” error message primary to help users.
To solve this problem, surround all of the values you want to print to the console in parenthesis:
for s in students: if s.startswith("A") == True: print(s) print("Above are all the students whose names begin with A.")
You have enclosed the “s” on the print
line of code in parenthesis. You have also enclosed the last string you print to the console in parenthesis. Let’s see if the program works:
Alex Alexander Above are all the students whose names begin with A.
Our code shows us that there are two students whose names begin with an A. Once our list of students has been iterated over, our program prints out a message that describes the output.
Conclusion
The Python “SyntaxError: Missing parentheses in call to ‘print’” error is raised when you try to print a value to the console without enclosing that value in parenthesis.
To solve this error, add parentheses around any statements you want to print to the console. This is because, in Python 3, print
is not a statement. It is a function. You must call a function using parentheses if you want to run it.
Now you have the knowledge you need to fix this common Python error like a pro!
If you are a Python developer, you might have encountered the error message “SyntaxError: Missing parentheses in call to ‘print’” at some point in your coding journey. This error message is usually displayed when you try to print a string or a variable without enclosing it in parentheses, that is, you’re trying to use the Python 2 syntax in a Python 3 environment which requires parentheses with print
. In this tutorial, we will discuss how to fix this error in Python.
Find Your Bootcamp Match
- Career Karma matches you with top tech bootcamps
- Access exclusive scholarships and prep courses
Select your interest
First name
Last name
Phone number
By continuing you agree to our Terms of Service and Privacy Policy, and you consent to receive offers and opportunities from Career Karma by telephone, text message, and email.
SyntaxError: Missing parentheses in call to ‘print’
Python 3 is the third major update to the programming language. In recent years, it has become the preferred version of Python to use.
Python 3 changed the way that print statements are written. The standalone print
statement works in Python 2 and prints a statement to the console.
In Python 3, print
is a function. This means you need to surround the contents of the string you want to print to the console in parenthesis like you do with any ordinary function call.
An Example Scenario
Write a program that prints out the names of all the students in a fourth grade class whose names begin with “A”. To start, define a list that contains the names of the students in the class:
students = ["Alex", "Alexander", "Piper", "Molly", "Hannah"]
Next, write a for loop that iterates over all the items in this list. In the for loop, we’ll use an if
statement to check if each name begins with “A”:
for s in students: if s.startswith("A") == True: print s
The startswith() method checks if a string starts with a particular character or set of characters. The code checks whether each name in the “students” list begins with “A”.
Add an extra print statement to the end of the code that tells us the program has finished running:
print "Above are all the students whose names begin with A."
Now you’re ready to run the program:
File "main.py", line 5 print s ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(s)?
The code informs us that there is a syntax error in the program.
The Solution
Handily, Python already offers the solution to the problem in the error message.
This is because, in previous versions of Python 3, forgetting to include parenthesis around a print statement raised an error which only showed “invalid syntax”. This message is ambiguous because invalid syntax can be caused by a number of issues. Thus, Python introduced the new “missing parenthesis” error message primary to help users.
To solve this problem, surround all of the values you want to print to the console in parenthesis:
for s in students: if s.startswith("A") == True: print(s) print("Above are all the students whose names begin with A.")
You have enclosed the “s” on the print
line of code in parenthesis. You have also enclosed the last string you print to the console in parenthesis. Let’s see if the program works:
Alex Alexander Above are all the students whose names begin with A.
Our code shows us that there are two students whose names begin with an A. Once our list of students has been iterated over, our program prints out a message that describes the output.
Conclusion
The Python “SyntaxError: Missing parentheses in call to ‘print’” error is raised when you try to print a value to the console without enclosing that value in parenthesis.
To solve this error, add parentheses around any statements you want to print to the console. This is because, in Python 3, print
is not a statement. It is a function. You must call a function using parentheses if you want to run it.
Now you have the knowledge you need to fix this common Python error like a pro!