Syntaxerror missing parentheses in call to print

Are you wondering why syntaxerror missing parentheses in call to print appear in your Python code?

Well, this error is easy to troubleshoot. You just have to keep reading.

In this article, we’ll walk you through troubleshooting the missing parentheses in call to print, a SyntaxError in Python.

So let’s grind to enhance your programming skills.

What is “syntaxerror missing parentheses in call to print”?

The syntaxerror: missing parentheses in call to print occurs when you are trying to use an outdated “print” statement (print ‘sample’) in Python version 3 or when you forgot to call print() as a function.

For example:

print "Hi, Welcome to Itsourcecode!"

Output:

 File "C:\Users\pies-pc2\PycharmProjects\pythonProject\main.py", line 1
    print "Hi, Welcome to Itsourcecode!"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

Note: You have to add parentheses around the value to be printed because ‘print’ statement has been replaced with the print() function in Python version 3.

Why does the “missing parentheses in call to print” SyntaxError occur?

The error message syntaxerror: missing parentheses in call to ‘print’ occurs when you are trying to use a Python 2 “print’” statement in Python 3.

The print function is used to display output on the console or terminal in Python. However, it requires parentheses to enclose the content being printed.

When these parentheses are missing, Python raises a syntax error to indicate that there is a problem with the code structure.

How to fix “syntaxerror missing parentheses in call to print”?

To fix the syntaxerror: missing parentheses in call to ‘print,’ ensure to add parentheses () around the value you want to print.

For instance, instead of writing print “Hey!”, you should write print(“Hey”)

The following are the solutions that you can use to resolve this error.

Solution 1: Use print() as a function

In Python 3 and later versions, the print() statement has become a function. To use it correctly, you need to include parentheses when calling it.

For example:

Incorrect code

print "Hi, Welcome to Itsourcecode!"

This will cause a syntaxerror probably because you are using the old code in Python version 3. In Python 3, you can’t use print as a standalone expression anymore.

Corrected code

print ("Hi, Welcome to Itsourcecode!")

Output:

Hi, Welcome to Itsourcecode!

Here’s another example:

website = 'Itsourcecode'

print('My favorite website for IT is ' + website) 

Output:

My favorite website for IT is Itsourcecode

Solution 2: Use print() function with formatted string literals

Python 3 brings an exciting enhancement called formatted string literals, or f-strings, along with the print() function.

One of the handy benefits of using f-strings is that you can easily combine values of different types, like numbers and words, without the need to convert them to strings explicitly.

To create an f-string, you just need to put an “f” or “F” before the string and include expressions within curly braces ({}).

For example:

websitename = 'Itsourcecode'

visits = 1000000


print(f'website name: \n {websitename} \n visits: {visits * 3}')

Output:

website name: 
 Itsourcecode 
 visits: 3000000

Solution 3: Add an import statement to import the print function

To ensure compatibility between Python 2 and Python 3, you have the option to import the “print” function from the future module by adding an import statement to your code.

For example:

from __future__ import print_function

print('Hi, Welcome to Itsourcecode!')

Now, you can use print as a function in Python version 2.

Output:

Hi, Welcome to Itsourcecode!

Conclusion

In conclusion, the syntaxerror: missing parentheses in call to print occurs when you are trying to use an outdated “print” statement (print ‘sample’) in Python version 3 or when you forgot to call print() as a function.

To fix the error ensure to add parentheses () around the value you want to print.

For instance, instead of writing print “Hey!”, you should write print(“Hey”)

This article already discussed what this error is all about and multiple ways to resolve this error.

By executing the solutions above, you can master this SyntaxError with the help of this guide.

You could also check out other SyntaxError articles that may help you in the future if you encounter them.

We are hoping that this article helps you fix the error. Thank you for reading itsourcecoders 😊

Leave a Comment