List count() method Python

The list count() method determines the number of times a particular element occur in a list object

>>> ls=[22 , 67 , 46 , [34,] , [34,] , (0) , 22 , 'Test' , (0) , 656 , 'new' , 22 , 34 , 0 ]
>>> ls.count( 34 )
1
>>> ls.count( [34])
2
>>> ls.count( [34,])
2
>>> ls.count( 0 )
3
>>> ls.count( (0) )
3

Note [34,] is treated different from 34,so [34,] count is 2 but 34 count is 1.



Leave a Reply

Your email address will not be published. Required fields are marked *