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.
Understanding the Error
Before we dive into the solution, let’s first understand what this error message means. This error occurs when you’re trying to use the print
syntax of Python 2 in a Python 3 environment. You can check your Python version using the sys
module in Python.
import sys print(sys.version)
Output:
3.8.12 | packaged by conda-forge | (default, Oct 12 2021, 21:25:50) [Clang 11.1.0 ]
You can see that we’re using Python 3 (specifically, Python 3.8.12). Now, if you try to use the Python 2 syntax of print
in Python 3, you’ll get an error.
print "Hello, World!"
Output:
Cell In[10], line 1 print "Hello, World!" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, World!")?
We get the SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, World!")?
. The error message also suggests how we can correct the above error.
Note that print
is treated as a statement in Python 2 while in Python 3, print
is a function. This means that in Python 2, you can simply write print "Hello, world!"
to print a message to the console, while in Python 3, you need to use parentheses and write print("Hello, world!")
.
Fixing the error
To fix this error, you simply need to enclose the string or variable in parentheses. Here’s an example:
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.
print("Hello, World!")
Output:
Hello, World!
We don’t get an error and the value inside the print()
function is printed out.
Conclusion
In this tutorial, we discussed how to fix the “Missing parentheses in call to ‘print'” error in Python. This error message is usually displayed when you forget to enclose a string or variable in parentheses while using the print
function. By enclosing the string or variable in parentheses, you can fix this error and display the output on the console.
You might also be interested in –