On this page
len
Prev: iter | Up: __builtins__ | Next: license
Rel: all, any, enumerate, filter, iter
Ref: docs.python.org — len
Tags: #public #python3 #builtins
Import & Availability
# Built-in (available globally without import)
from builtins import len
Overview & Signature
len(obj, /)
Return the number of items in a container.
Usage
assert len([1, 2, 3]) == 3
assert len("café") == 4
assert len("café".encode("utf-8")) == 5
Gotchas
- $O(1)$ on built-in collections: Does not work on generators or iterators (they have no precomputed length).
REPL Inspect
help(len)
Linked from
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/iter Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/license Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/all Linked here; shared tags: #builtins
- tuts/python3/__builtins__/any Linked here; shared tags: #builtins
- tuts/python3/__builtins__/enumerate Linked here; shared tags: #builtins
- tuts/python3/__builtins__/filter Linked here; shared tags: #builtins
- tuts/c/builtins shared tags: #builtins
- tuts/c/builtins/__FILE__ shared tags: #builtins