Operator.countOf()
is used to count the number of occurrences of b
in a
. Counts the number of occurrences of a value.
Syntax: Operator.countOf (freq = a, value = b)
Parameters:
freq: It can be list or any other data type which store value
value: It is value for which we have to count the number of occurrencesReturns: Count of number of occurrences of value.
Example # 1: Use Operator.countOf ()
to count the number of occurrences of a given value in the list.
|
Exit:
Number of occurrence of b in arr1 = 2 Number of occurrence of e in arr1 = 0 Number of occurrence of 3 in arr = 3
Example # 2: Use Operator.countOf ()
to count the number of occurrences of a given value in the dictionary.
|
Output:
< pre> Number of occurrence of three in dict = 3 Number of occurrence of one in dict = 2 Number of occurrence of four in dict = 0 Example # 3: Use Operator.countOf ()
to count the number of occurrences of a given value in tuples.
|
Output:
Number of occurrence of b in tuple1 = 2 Number of occurrence of e in tuple1 = 0 Number of occurrence of 3 in tuple = 3