Python List count() method
Description
The count() method counts how many times an element appears in a list.
Syntax
count() method syntax:
list.count(obj)
Parameters
- obj -- the object to count in the list.
Return Value
Returns the number of times the element appears in the list.
Example
The following example shows how to use the count() function:
#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc', 123];
print "Count for 123 : ", aList.count(123);
print "Count for zara : ", aList.count('zara');
The output of the above example is:
Count for 123 : 2
Count for zara : 1
Python Lists