.count()
Anonymous contributor
Anonymous contributor3077 total contributions
Anonymous contributor
Published May 5, 2021Updated Jul 29, 2023
Contribute to Docs
Searches a list for a particular item and returns the number of matching entries found.
Syntax
list.count(value)
The .count()
method has just one parameter:
value
: The string to search for. (Required)
Example
To count the number of 'pen'
within the backpack
list:
backpack = ['pencil', 'pen', 'notebook', 'textbook', 'pen', 'highlighter', 'pen']numPen = backpack.count('pen')print(numPen)
This results in the following output:
3
All contributors
- Anonymous contributorAnonymous contributor3077 total contributions
- hitesh_mittal3 total contributions
- christian.dinh2481 total contributions
- Anonymous contributor
- hitesh_mittal
- christian.dinh
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.