In Python 2.7 both the following will do the same
print("Hello, World!") # Prints "Hello, World!"
print "Hello, World!" # Prints "Hello, World!"
However the following will not
print("Hello,", "World!") # Prints the tuple: ("Hello,", "World!")
print "Hello,", "World!" # Prints the words "Hello, World!"
In Python 3.x parenthesis on print
is mandatory, essentially making it a function, but in 2.7 both will work with differing results. What else should I know about print
in Python 2.7?
print
is actually a special statement, not a function. This is also why it can't be used like:lambda x: print x
Note that(expr)
does not create a Tuple (it results inexpr
), but,
does.from __future__ import print_function