def powers(a):
return a, a*a, a*a*a
a, square, cube = powers(10)
print(a, square, cube)
the last two lines could be refactored as:
print(*powers(10))
This technique is ineffective in Python 2, where print is a statement and the syntax would be invalid.
Python 3 just cleans off those little last ugly bits of Python. Lovely.
ReplyDeletewell, in python 2.5, the following works...
ReplyDeleteprint powers(10)
not much of a difference... ;)
forget it, I read to fast, your point is valid. sorry.
ReplyDeleteNice find!
ReplyDeleteprint(powers(10))
ReplyDeleteworks fine in python 2.5, 2.6. Why it shouldn't be used that way?
@নাসিম: That will produce output, but the output it produces will be the strr() of the resulting tuple, including the parentheses and commas.
ReplyDeleteIn Python 3 the elegant syntax for tuple expansion passes each value as an individual argument to print(), and each value returned appears as a number.
Even if you have redefined the print() function (as one can validly do in Python 3) the updated function will operate correctly.
You can use this import in 2.6 to run the code.
ReplyDeletefrom __future__ import print_function