PEP 234: Iterators

Alex Martelli aleaxit at yahoo.com
Thu May 3 05:33:21 EDT 2001


"Andrew Dalke" <dalke at acm.org> wrote in message
news:9cqr4q$79q$1 at nntp9.atl.mindspring.net...
    [snip]
> Is there another case in Python where a single function has
> such different expectations on its input depending on the
> number of parameters?  The closest I could come up with is
> string.split, which isn't all that close.

Builtin function int() isn't all that close either, but,
anyway -- when called with two parameters the first one
must be a string; when with one, it may still be a string
BUT it may also be a number.  long() is similar.

max() and min() *ARE* EXTREMELY different when called
with one argument, or with many.  If only one argument,
it must be a sequence, and the maximum or minimum item
of that sequence is returned.  If 2 or more arguments,
then the "sequencehood", if any, of arguments is totally
ignored, and the max or min *argument* is returned.

It might be argued that range(x) and range(x,y) treat
x very differently (as upper-bound and lower-bound
respectively).  slice() and xrange() are similar.


Alex






More information about the Python-list mailing list