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

Matteo Dell'Amico della at toglimi.linux.it
Thu Jul 29 11:10:46 EDT 2004


Peter Hansen wrote:
> Actually, not in the least, but I'm happy to go on faith that
> you have a point and hope you have managed to communicate it
> to others. :-|

Let's try it again: in functional programming languages, you can use 
pattern-matching, so that you can define functions in a declarative 
fashion this way:

f(1) = 2
f(2) = 3
f(3) = 4
f(_) = 42

In python, this could be written as:

def f(x):
     if x == 1:
         return 2
     elif x == 2:
         return 3
     elif x == 3:
         return 4
     else:
         return 42

'_' is the identifier that means "anything here".

-- 
Ciao,
Matteo



More information about the Python-list mailing list