Python len() Function

Returns the length of an object. This is useful for determining the length of string or array and the the number of items in a collection (list, dictionary, set, or tuple.)

Syntax

Python
len(container)

Parameters

ParameterDescription
container Required. The container containing the items to count.

Example

Python
string = "Hello World"
print(len(string))

myList = ['apples', 'oranges', 'bananas']
print(len(myList))

fish = fish = {
    'guppy': 2,
    'zebra' : 5,
    'betta': 10,
    'minnow': 3
}
print(len(fish))

Output

11
3
4