March 2003
Intermediate to advanced
656 pages
39h 30m
English
__len__
__len__(self)
The
len(
x
)
built-in function call, and other built-in functions that need to
know how many items are in container x,
call x
.__len__( ).
__len__ should return an int,
the number of items in x. Python also
calls x
.__len__( ) to
evaluate x in a Boolean context, if
__nonzero__ is absent. Absent __nonzero__, a container is taken as false if and only if
the container is empty (i.e., the container’s length
is 0).