What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
If you’ve recently switched from Python 2 to Python 3 (or are following outdated tutorials), you may have encountered this error message:
SyntaxError: Missing parentheses in call to 'print'
In Python 2, print
was a statement, meaning you could write:
print "Hello World"
without parentheses. But in Python 3, print
is now a function, which requires parentheses:
print("Hello World")
The error typically means you tried to call print
the old Python 2 way. Simply adding parentheses fixes the issue.
Why the Change?
- Consistency: Treating
print
as a function harmonizes it with other built-in functions in Python 3. - Extensibility: Having
print("Hello", "World", sep=", ")
or passing keyword arguments is cleaner whenprint
is a function.
How to Fix It
- Short Answer: Add parentheses around the items you want to print:
# WRONG in Python 3: print "Hello World" # RIGHT in Python 3: print("Hello World")
- Batch Conversion: If you have many scripts, you can use the
2to3
tool to automatically convert Python 2 print statements to Python 3 function calls.
Bonus Tips
-
Using Python 2 and 3 Together
If you need code that runs on both Python 2 and Python 3 without modification, addfrom __future__ import print_function
at the top of your Python 2 files. This enforces Python 3–styleprint
behavior in Python 2. -
Check Your Tutorials
Many older examples on the web still use Python 2 syntax. Always verify if the tutorial is Python 2 or Python 3 based, especially when seeing errors aboutprint
.
Want to Master Python?
If you’re ready to strengthen your Python 3 skills further, here are a couple of highly recommended courses from DesignGurus.io:
-
Grokking Python Fundamentals
A comprehensive course covering everything from basic syntax to advanced Python concepts, ensuring you code with modern best practices (including the correct use ofprint
!). -
Grokking the Coding Interview: Patterns for Coding Questions
If you’re preparing for coding interviews, this course breaks down the most common coding patterns and shows you how to apply them in Python.
Growing Beyond Python
As you progress, especially if you’re aiming for jobs at top tech companies, knowing system design is crucial alongside coding. Here are some additional resources:
- Grokking System Design Fundamentals – Ideal for beginners looking to understand the basics of designing scalable systems.
- Grokking the System Design Interview – Perfect for tackling design questions in FAANG/MAANG and other top-tier interviews.
You can also check out the DesignGurus YouTube Channel for free videos on system design and coding patterns, such as:
Final Thoughts
Whenever you see SyntaxError: Missing parentheses in call to 'print'
in Python, it’s almost certainly a sign you’re using Python 2 print statements in a Python 3 environment. Adding parentheses fixes the issue immediately. For a smooth coding experience, ensure you’re following Python 3 tutorials and keep your environment consistent.
Happy Coding!