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
Copy Code
len(container)
Parameters
Parameter | Description |
---|---|
container |
Required. The container containing the items to count. |
Example
Python
Copy Code
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