count() Method :-
Python में किसी List, Tuple या String में किसी particular element की frequency पता करने के लिए count() method का उपयोग किया जा सकता है।
count() method यह बताता है कि दिया गया element collection में कितनी बार मौजूद है।
Syntax :-
collection.count(element)
Example :-
numbers = [10, 20, 10, 30, 10, 20]
frequency = numbers.count(10)
print("Frequency of 10:", frequency)
Output:
Frequency of 10: 3
Explanation :-
यहाँ:
numbers = [10, 20, 10, 30, 10, 20]
और:
numbers.count(10)
List में 10 की frequency count करता है।
10 List में 3 times मौजूद है, इसलिए output:
Frequency of 10: 3
IN ENGLISH -
count() Method :-
In Python, the count() method can be used to find the frequency of a particular element in a List, Tuple, or String.
The count() method tells us how many times the given element is present in the collection.
Syntax :-
collection.count(element)
Example :-
numbers = [10, 20, 10, 30, 10, 20]
frequency = numbers.count(10)
print("Frequency of 10:", frequency)
Output :-
Frequency of 10: 3
Explanation :-
Here:
numbers = [10, 20, 10, 30, 10, 20]
And:
numbers.count(10)
counts the frequency of 10 in the List.
10 is present 3 times in the List, so the output is:
Frequency of 10: 3