Why would I get a TypeEror?

harold fellermann harold.fellermann at upf.edu
Wed Jan 12 19:12:44 CET 2005


On 12.01.2005, at 18:35, It's me wrote:

> For this code snip:
>
> a=3
> ....
> b=(1,len(a))[isinstance(a,(list,tuple,dict))]
>
> Why would I get a TypeError from the len function?

because len() works only for sequence and mapping objects:

 >>> help(len)
Help on built-in function len in module __builtin__:

len(...)
     len(object) -> integer

     Return the number of items of a sequence or mapping.

- harold -

--
Ceci n'est pas une signature.
--




More information about the Python-list mailing list