.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:

Example 2

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

Edit this page on GitHub

Contributors

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

Learn Python on Codecademy

Edit this page on GitHub

Contributors