← All references

len()

len(obj)

Return the length of a sequence or collection.

len()

Returns the number of items in an object. Works on strings, lists, tuples, dicts, sets, and any object that implements __len__.

Example

print(len("hello"))        # 5
print(len([1, 2, 3, 4]))  # 4
print(len({"a": 1}))      # 1
print(len((10, 20)))      # 2