capypad
0 day streak
python / beginner
Snippet

Finding the Length of a List

The len() function is a built-in tool that tells you exactly how many items are inside a list or any other collection. It is one of the most frequently used functions in Python.

snippet.py
python
1
2
3
4
colors = ["red", "blue", "green", "yellow"]
count = len(colors)
 
print("Number of colors:", count)
Breakdown
1
count = len(colors)
Passes the list to the len function to retrieve the total count of elements.