A colleague is trying to run a Python 2 script in a Python 3 environment, and the script fails due to a syntax error in the print statement. What would be the likely cause?

  • Python 2 has a different file encoding
  • Python 2 requires a __future__ import
  • Python 2 uses print as a function
  • Python 2 uses print as a statement
The likely cause of the syntax error is that Python 2 uses print as a statement, while Python 3 uses it as a function. In Python 3, you need to use parentheses, like print("Hello, World!"), whereas in Python 2, you can use print "Hello, World!".
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *