Method Name:
count
Method Signature:
count()
Overview:
- The method returns the number of times an element appears in the list.
- To find the number of elements in a list use the len() function.
Parameters:
element - The element whose occurence in the list needs to be counted.
Return value:
None
Example 1:
# Example Python program that finds the number of occureneces of an item in a list # Create a list # Element to find # Number of elements found # Element to find # Number of elements found |
Output:
There are 2 Curtains in the list There are 1 TVs in the list |
Example 2:
# Example Python program that finds the number def __eq__(self, object): # Create doors # Create a list of doors # Find doors whose width = 3, height = 9, thickness = 0.2 |
Output:
Doors found with the same attributes: 3 |