SyntaxStudy
Sign Up

len()

function

Returns the number of items in a container (string, list, tuple, dict, set, etc.).

Syntax

len(s)

Example

python
print(len('hello'))       # 5
print(len([1, 2, 3]))     # 3
print(len({'a': 1}))      # 1
print(len((1, 2, 3, 4)))  # 4
print(len({1, 2, 3}))     # 3