Built-in functions and keyword arguments

Jean-Paul Calderone exarkun at divmod.com
Mon Oct 29 18:37:42 CET 2007


On Mon, 29 Oct 2007 19:03:34 +0200, Hendrik van Rooyen <mail at microcorp.co.za> wrote:
>"Tim Chase" <python.list at tim.thechases.com>
>
>> > I think you are being a little bit unfair here: help(len) says:
>> >
>> > len(...)
>> >     len(object) -> integer
>> >
>> >     Return the number of items of a sequence or mapping.
>> >
>> > which implies that the argument to len has the name 'object' (although in
>> > fact it doesn't have a name).
>>
>> And to confound matters even further for the uninitiated,
>>
>> http://docs.python.org/lib/built-in-funcs.html#l2h-45
>>
>> says that it's "len(s)" instead (but "len(s=[])" doesn't work either)
>
>Looks like a gotcha to me - its the difference between a keyword
>(master = 42) and an assignment  (s='I am a string')
>

But it's not a keyword:

  >>> len(s=[])
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  TypeError: len() takes no keyword arguments
  >>>

I think that's the issue here.

Jean-Paul



More information about the Python-list mailing list