what does 'for _ in range()' mean?
Tor Iver Wilhelmsen
tor.iver.wilhelmsen at broadpark.no
Wed Jul 28 05:06:18 EDT 2004
Roy Smith <roy at panix.com> writes:
> I've never heard of that convention before. Is it some python-specific
> thing, or is my ignorance more global in scope?
It may derive from Prolog, where you use _ as an unbound "wildcard".
E.g. to declare that X is a parent if X is a father or mother:
parent(X) :- fatherOf(X, _), !.
parent(X) :- motherOf(X, _), !.
because you don't need to know anything about the child, just that it
exists. If you used a variable like Y, you would either also need to
say something about Y, or Y would end up in the resolved answer.
(The ! is a "cut", and means we're not interested in more than one
answer.)
More information about the Python-list
mailing list