In Python, to print a data value on the console, we use the print function. The print function accepts the data value as an argument and prints it on the console window when we execute the program. Like all the other functions to call the print function, we use the
print
name, followed by the set of close parentheses. And if we do not use the parentheses for the print function and miss them, we will receive the
SyntaxError: Missing parentheses in call to 'print'
Error.
In this guide, we will discuss the following error in detail and see why it occurs in a Python program. We will also discuss an example that demonstrates the error. So without further ado, let's get started with the error statement.
Python Problem SyntaxError: Missing parentheses in call to 'print'
As a programing language, Python follows a syntax to write the program. When we want to print some output or data on the console window, we use the print statement and pass the data inside the parentheses.
Example
>>> print("Data")
Data
But if we miss the parentheses and try to print the data value, we will encounter the
SyntaxError: Missing parentheses in call to 'print'
Error
>>> print "Data"
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Data")?
The error statement has two messages, Exception Type and Message error.
- SyntaxError (Exception Type)
- Missing parentheses in call to 'print' (Error Message)
1. SyntaxError
SyntaxError is a standard Python exception that is raised in a Python program when we write the wrong syntax. Syntax defines the pattern in which the code must be written so the interpreter can parse and execute it. In the above example, print does not follow the parentheses, which is the wrong syntax according to Python. That's why it raises the SyntaxError.
2. Missing parentheses in call to 'print'
This statement is the Error message, and just by reading it, we can tell what it is trying to tell us. This error message only occurs in a Python program when we forget to put the parentheses after the print statement.
Common Example Scenario
We have a list of employee names, and we need to print only those students' names whose names started with A or E. Let's begin with initializing the employee list
employee = ["Kasturba","Sneha", "Esha", "Anshula","Ajeet", "Megha","Anshu","Arjun","Tulsi","Kartik" ]
Now loop through the employee list using for loop and print the names that start with A or E.
for name in employee:
if name.lower().startswith("a") or name.lower().startswith("e"):
print name
Output
File "main.py", line 5
print name
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(name)?
Break the Output
The following example throws the SyntaxError with Missing parentheses for the
print
statement. In the above example, we received the error because when we tried to print the name on the console window using the
print
statement, there we have not used the parentheses for the
print
function.
Solution
To solve the above error, all we need to do is put the parentheses after the
print
statement and pass the
name
identifier inside that parentheses.
employee = ["Kasturba","Sneha", "Esha", "Anshula","Ajeet", "Megha","Anshu","Arjun","Tulsi","Kartik" ]\
for name in employee:
if name.lower().startswith("a") or name.lower().startswith("e"):
print(name) #solved
Output
Esha
Anshula
Ajeet
Anshu
Arjun
Now our code runs without any error.
Conclusion
The "SyntaxError: Missing parentheses in call to 'print'" error is raised in a Python program when we forget to put the parentheses after the print function name. This is a very common Python error, and with the all-new IDE's syntax highlight feature, you will find this error before executing the program. Because modern IDEs provide come with basic syntax debugging features.
If you are still getting this error in your Python code, feel free to post your code and query in the comment section. We will try to help you in debugging.
People are also reading:
- Python TypeError: ‘NoneType’ object is not subscriptable Solution
- Analyze Sentiment Using VADER in Python
- Python NameError name is not defined Solution
- Reverse a String in Python
- Python SyntaxError: ‘return’ outside function Solution
- Extract Images from PDF in Python
- Python indexerror: list index out of range Solution
- Multi-line Comments in Python
- Python typeerror: ‘str’ object is not callable Solution
- Barcode Reader in Python
Leave a Comment on this Post