Logo

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?

  1. Consistency: Treating print as a function harmonizes it with other built-in functions in Python 3.
  2. Extensibility: Having print("Hello", "World", sep=", ") or passing keyword arguments is cleaner when print 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

  1. Using Python 2 and 3 Together
    If you need code that runs on both Python 2 and Python 3 without modification, add from __future__ import print_function at the top of your Python 2 files. This enforces Python 3–style print behavior in Python 2.

  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 about print.

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:

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:

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!

TAGS
Python
CONTRIBUTOR
TechGrind