SoFunction
Updated on 2024-11-17

Tutorial on using methods in Python

The count() method returns the number of times the obj appears in the list.
grammatical

The following is the syntax of the count() method:

(obj)

parameters

  • obj -- This is the object being counted in this list.

return value

This method returns the number of times the obj appears in the list.
(for) instance

The following example shows the use of the count() method.

#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc', 123];

print "Count for 123 : ", (123);
print "Count for zara : ", ('zara');

When we run the above program, it produces the following results:

Count for 123 : 2
Count for zara : 1