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

Matteo Dell'Amico della at toglimi.linux.it
Thu Jul 29 19:17:56 EDT 2004


Peter Hansen wrote:

> I'm just as unsure about any of that.  It seems more likely to
> me that a number of people have independently found _ to be a handy
> "anonymous" variable in different situations, and that trying to find
> links to analogous usage in other languages is largely speculative.

It would surprise me if the three were unrelated... there are 
similarities between prolog's unification, ML's pattern matching and 
python's tuple unpacking (even if the latter is considerably simpler and 
less powerful), and note that the specific meaning of _ - both in Prolog 
and in ML-like languages - is "throw away": if I'm not mistaken, you can 
always replace an underscore with a new unused variable.

> Of course, that said, we'll probably hear shortly from someone
> channelling the person who added it to the interpreter as the
> "last result" name, contra-dicting me. :-)

I see this one as a totally unrelated meaning, similar to perl's $_. I'm 
waiting to be contradicted, too. :-)

-- 
Ciao,
Matteo



More information about the Python-list mailing list