Search code examples
pythonprintingsyntax-error

invalid syntax print in Python 3.3.0


When I try this at the REPL in Python 3.3:

>>> def fact(n):
...     res = 1
...     while n > 1: 
...     res *= n
...     n -= 1
...     return res
...
>>> print fact(23)

I get SyntaxError: invalid syntax. Why?


Solution

  • In python 3.x print is a function. Try print(fact(23)) instead.