len(s)

The len() function returns the number of items in a specified container object.

Parameters

The len() function takes one argument, s, which can be a:

  • sequence: string, bytes, tuple, list, or range
  • collection: dictionary, set, or frozenset

Return Value

The len() function returns the number of elements in the object. Passing no argument or an invalid argument raises a TypeError.

Examples

len([1, 2, 'a'])  # 3
len({'a': 'aa', 'b': 'bb'})  # 2
len('some')  # 4