Name
__len__
Synopsis
__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
).
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.