Size of list

Schüle Daniel uval at rz.uni-karlsruhe.de
Mon Feb 6 14:04:35 EST 2006


 >>> lst = [1,2,3]
 >>> len(lst)
3
 >>> lst.__len__()
3

in genereal all objects which implements __len__
can be passed to built-in function len
 >>> len
<built-in function len>

just to give one example how this can be used

 >>> class X(object):
...     def __len__(self):
...             print "this instance has __len__"
...             return 100
...
 >>> x=X()
 >>> len(x)
this instance has __len__
100
 >>> x.__len__()
this instance has __len__
100

hth, Daniel




More information about the Python-list mailing list