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 😊

Frequently Asked Questions

What is Python SyntaxError and what causes it?

SyntaxError is raised when Python’s parser can’t understand your code. Common causes: missing colon (def foo() instead of def foo():), unmatched parentheses or brackets, incorrect indentation, mixing tabs and spaces, missing comma in a list, or using a Python 3 feature in a Python 2 interpreter (or vice versa). The error points to a line, but the actual issue is often on the line BEFORE.

How do I fix ‘unexpected EOF while parsing’?

Python ran out of code while expecting more, usually unclosed parenthesis, bracket, brace, or quote. Scroll up from the error line and count opening vs closing pairs. Use an IDE with bracket matching (VS Code, PyCharm) to highlight pairs. Common gotcha: a triple-quoted string that’s missing its closing triple-quote.

Why does my syntax error point to a line that looks correct?

The actual error is often on the line BEFORE the one Python reports. Python reads code until something doesn’t parse, then reports the position where it gave up, not where the user’s mistake started. Check the line above the reported error for missing colons, commas, or closing brackets.

Why does ‘print x’ raise SyntaxError in Python 3?

Python 3 made print a function, so print(x) is required. The bare ‘print x’ syntax was Python 2 only. If you’re following an old tutorial, check whether it targets Python 2 (released 2008) or Python 3 (your current interpreter). Update all print statements to print(…) function calls.

Where can I find more SyntaxError fixes?

Browse the SyntaxError reference hub for 48+ specific fixes (Python and JavaScript). For Python fundamentals see the Python Tutorial hub. For JavaScript syntax errors see the JavaScript Tutorial hub.

Leave a Comment