what does 'for _ in range()' mean?
Terry Reedy
tjreedy at udel.edu
Thu Jul 29 21:09:07 EDT 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
> ...
> 2
> 5
> 8
So does
>>> for a,v,a in [[1,2,3], [4,5,6]]: print v
...
2
5
too much fuss over simplicity yours
Terry J. Reedy
More information about the Python-list
mailing list