Print "string" and print("string")


#1

Hello

How come we can use the print function without parenthesis?
i.e

print "random sentence"
or
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?


#2

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


#3

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