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

Phil Frost indigo at bitglue.com
Wed Jul 28 21:13:14 CEST 2004

At Some Point, Someone Asked Something to The Effect of:
> where does this _ thing come from?

In ML, _ is used as magic "don't care" variable. It's often used when
unpacking tuples and some elements are irrelevant. Example:

let (fu, bar, _, _) = returns_a_4_tuple ()

(fu, bar, _, __) = returns_a_4_tuple()

One difference is that _ is allowed multiple times in Ocaml, while in
Python it is not. Also to Python, it's a variable like any other, while
in Ocaml it's magic.

More information about the Python-list mailing list