.count()

Takes in a list of values of any data type, and returns the number of times(count) a particular value is present within the list.

Syntax

list.count()

Example 1

Use .count() to count the number of occurrences of the string "cat" in the pets list:

Code
Output
Loading...

Example 2

Use .count() to count the number of occurrences of the integer 3 in the treats_per_pet list:

Code
Output
Loading...

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy

Contributors