how to fix missing parentesis in call to print error

How to Fix – SyntaxError: Missing parentheses in call to ‘print’

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.

how to fix missing parentesis in call to print error

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:

📚 Data Science Programs By Skill Level

Introductory

Intermediate ⭐⭐⭐

Advanced ⭐⭐⭐⭐⭐

🔎 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 –

Author

  • Piyush Raj

    Piyush is a data professional passionate about using data to understand things better and make informed decisions. He has experience working as a Data Scientist in the consulting domain and holds an engineering degree from IIT Roorkee. His hobbies include watching cricket, reading, and working on side projects.

Scroll to Top