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

Peter Hansen peter at engcorp.com
Wed Jul 28 21:28:45 CEST 2004


Phil Frost wrote:

> Python:
> (fu, bar, _, __) = returns_a_4_tuple()
> 
> One difference is that _ is allowed multiple times in Ocaml, while in
> Python it is not. 

Why do you say that?

c:\>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) ....
 >>> a = 1, 2, 3, 4
 >>> b, c, d, e = a
 >>> b, c, d, d = a
 >>> b, c, _, _ = a
 >>> _, _, _, _ = a
 >>> _
4

Looks to me like Python doesn't care how many times it rebinds
a name while unpacking a tuple.

-Peter



More information about the Python-list mailing list