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

Matteo Dell'Amico della at toglimi.linux.it
Thu Jul 29 15:37:33 CEST 2004


Peter Hansen wrote:

> I have no idea what you are talking about; sorry.  The "code"
> you show is not valid, and since you aren't talking about a
> function *definition* (where duplicate names are disallowed)
> but apparently about calling a function, I can't see that this
> has the slightest thing to do with the topic at hand.

Of course this is not valid python code. :-)
This is a pseudo-functional language function definition. It is 
specified by pattern matching:

foo(a, a) = True

means that calling foo with a tuple of two identical arguments returns 
True, while

foo(_, _) = False

means that calling foo with a tuple of any two arguments returns False, 
if the above condition isn't met.

The goal was to put into evidence the use of pattern-matching and '_'. 
That's all. :-)

I hope this is clearer now...

-- 
Ciao,
Matteo



More information about the Python-list mailing list