How do you count in python?



How do you count in python?..

Answer / Gaurav Bansh

You can count elements in a list using the built-in `count()` method or by using a loop with the built-in `len()` function. For example: `my_list.count(element)` counts the number of occurrences of `element` in `my_list`. Or you can use a loop like this: `count = 0; for element in my_list: if element == target: count += 1`. The `len()` function returns the total number of elements in a collection.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is python db api?

1 Answers  


Does python has private keyword in python ?

1 Answers  


What is a numpy array?

1 Answers  


Differentiate between .py and .pyc files?

1 Answers  


name few python modules for statistical, numerical and scientific computations?

1 Answers  


Can I use notepad ++ for python?

1 Answers  


How do I sort a list in python 3?

1 Answers  


What is the difference between `list` and `tuple` in Python?

2 Answers  


What do you know about iterator protocol?

1 Answers  


What is difference between input and raw_input?

1 Answers  


What is use of list comprehension ?

1 Answers  


What is the purpose of __ init __?

1 Answers  


Categories