3 ms·
There is another, less obvious difference: in Python 2, if you print multiple items in parentheses, you're actually printing a tuple: >>> print "foo", 1, 2
by BerislavLopac 10y ago
There is another, less obvious difference: in Python 2, if you print multiple items in parentheses, you're actually printing a tuple:
>>> print "foo", 1, 2, "bar", "baz"
foo 1 2 bar baz
>>> print("foo", 1, 2, "bar", "baz")
('foo', 1, 2, 'bar', 'baz')
>>> from __future__ import print_function
>>> print("foo", 1, 2, "bar", "baz")
foo 1 2 bar baz
- geoelectric 10y agoTrue, that, behavior-wise. It's the comma that actually defines the tuple, though, hence (1) being different than (1,) and x = 1,2 assigning (1,2). In the particular case of a print statement, the grouping parens disambiguate between the comma meaning multiple args and a single arg that's a tuple, once Python 2 implicitly wraps the entire right side with function calling parens. In the end it's really a form of operator precedence. The from __future__ version behaves differently only because the function calling parens are now explicit and so tuple grouping parens must be added too if desired.