Length

The len() function returns the number of elements in a list.

File: len.py

cars = ['bmw', 'mercedes', 'audi', 'subaru']
print(len(cars))

which prints length of the list to the console

4

We can use the len() function to determine length of other data types different from lists. For example, we can determine the length of a string.

File: len.py

car = 'bmw'
print(len(car))

produces

3