Python - Get Number of Items in a List

In Python you can use the built-in len() function to get the number of elements in a list.

fruit = ['apple', 'pear', 'banana', 'kiwi']
num_fruit = len(fruit)
print(num_fruit) # 4

You can also use a list's count() method if you want to get the number of a specific item.

fruit = ['apple', 'peach', 'lemon', 'apple']
num_apples = fruit.count('apple') print(num_apples) # 2