Python List count () method
description
count () method is used to count the number of times an element that appears in the list.
grammar
count () method syntax:
list.count(obj)
parameter
- obj - the list of objects of the statistics.
return value
Returns the number of elements appear in the list.
Examples
The following example shows the count () function to use:
#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc', 123]; print "Count for 123 : ", aList.count(123); print "Count for zara : ", aList.count('zara');
Examples of the above output results are as follows:
Count for 123 : 2 Count for zara : 1