Print "string" and print("string")



How come we can use the print function without parenthesis?

print "random sentence"
print("random sentence")

Is there a scenario where you would use one over the other or is this just implemented like this in order for Python to be a more forgiving language in case the user forgets the parenthesis?


well, in python2 (what codecademy uses) print is a statement, so you shouldn't use parentheses, in python3, print is a function call, so you need parentheses.

using parentheses with print in python2 might even be problematic:

x = "world"
print("hello", x)

now we print a tuple (immutable list), not a string


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.