A Python 3 Idiom?
· pycon, python, python 3
Originally published at https://holdenweb.blogspot.com/2010/02/python-3-idiom.html
A while ago I wrote a short Python 3 snippet as an introduction to a post about factory functions. Second thoughts are proverbially the best, and I realised that in the following code: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.
pycon python python 3
