Definition:
If you need to count the values in a list, then it counts the number of times a value appears in the list.
List → a = [10, 20, 10, 30, 10]
Index : 0 1 2 3 4
↓ ↓ ↓ ↓ ↓
Value : 10 20 10 30 10
Method → a.count(10)
Counting → 10 10 10
↑ ↑ ↑
(1) (2) (3)
Result → x = 3
Syntax
list_name.count(value)
Example:
a = [10, 20, 10, 30, 10]
x = a.count(10)
print(x)
Output:
Exercise
Count how many times 5 appears in the list a = [5, 10, 5, 20, 5] using Python.
