what does 'for _ in range()' mean?
tjreedy at udel.edu
Fri Jul 30 03:09:07 CEST 2004
"Dave Benjamin" <ramen at lackingtalent.com> wrote in message
news:slrncgj6j3.vte.ramen at lackingtalent.com...
> In Python, it's possible to use _ multiple times in the same expression,
In Python, _ is a (non-keyword) name like any other. It can be used like
any other name. In interactive mode, it is the default name bound to bare
expressions, but it is still just a name.
> too. I guess there's no obvious reason why this shouldn't work, but I
> discovered the following tuple-unpacking idiom recently:
> >>> for _, val, _ in ((1, 2, 3), (4, 5, 6), (7, 8, 9)):
> ... print val
>>> for a,v,a in [[1,2,3], [4,5,6]]: print v
too much fuss over simplicity yours
Terry J. Reedy
More information about the Python-list