what does 'for _ in range()' mean?

Peter Hansen peter at engcorp.com
Wed Jul 28 06:50:40 EDT 2004


John Roth wrote:

> "David Eppstein" <eppstein at ics.uci.edu> wrote:
>> Jon Perez <jbperez808 at wahoo.com> wrote:
>>>I know that in the interpreter _ means the
>>>last value calculated, but what does _ mean
>>>inside source code?
>>
>>AFAIK it's just a variable like any other, but by convention it means
>>that you don't intend to use that value, just read it and ignore it.
> 
> What convention? I have to agree with a couple
> of other posters; I've never heard of it before.

I would imagine it's the same convention that suggests that
the value assigned to _ is ignored in the following type
of code, which surely most of us have seen around here a
few times:

a, b, _ = tupleWithThreeItems

-Peter



More information about the Python-list mailing list