Python | Operator.countOf Last Updated : 30 Sep, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Operator.countOf() is used for counting the number of occurrences of b in a. It counts the number of occurrences of 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 occurrences Returns: Count of number of occurrences of value. Example #1: Use Operator.countOf() to count the number of occurrences of given value in a list. Python3 1== # Python program showing # use of countOf() function # in a list from operator import * arr = [ 1, 2, 3, 3, 3 ] arr1 = [ 'a', 'b', 'c', 'b', 'd' ] print("Number of occurrence of b in arr1 =", countOf(arr1, "b")) print("Number of occurrence of e in arr1 =", countOf(arr1, "e")) print("Number of occurrence of 3 in arr =", countOf(arr, 3)) Output: 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 given value in a dictionary. Python3 1== # Python program showing # use of countOf() function # in a dictionary from operator import * d = {"score": 3, "score1": 1, "score2": 3, "score3": 1, "score4": 3} print("Number of occurrence of three in dict =",countOf(d.values(),3)) print("Number of occurrence of one in dict =",countOf(d.values(),1)) print("Number of occurrence of four in dict =",countOf(d.values(),4)) Output : 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 given value in a tuples. Python3 1== # Python program showing # use of countOf() function # in a tuples from operator import * tup = ( 1, 2, 3, 3, 3 ) tup1 = ( 'a', 'b', 'c', 'b', 'd' ) print("Number of occurrence of b in tuple1 =",countOf(tup1,"b")) print("Number of occurrence of e in tuple1 =",countOf(tup1,"e")) print("Number of occurrence of 3 in tuple =",countOf(tup,3)) 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 Comment More infoAdvertise with us Next Article Python | Operator.countOf G garg_ak0109 Follow Improve Article Tags : Python Python-Operators Python-Built-in-functions Practice Tags : pythonpython-operators Similar Reads Python Operators In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /, 6 min read Python - Itertools.count() Python Itertools are a great way of creating complex iterators which helps in getting faster execution time and writing memory-efficient code. Itertools provide us with functions for creating infinite sequences and itertools.count() is one such function and it does exactly what it sounds like, it co 3 min read Python Bitwise Operators Python bitwise operators are used to perform bitwise calculations on integers. The integers are first converted into binary and then operations are performed on each bit or corresponding pair of bits, hence the name bitwise operators. The result is then returned in decimal format.Note: Python bitwis 5 min read Comparison Operators in Python Python operators can be used with various data types, including numbers, strings, boolean and more. In Python, comparison operators are used to compare the values of two operands (elements being compared). When comparing strings, the comparison is based on the alphabetical order of their characters 4 min read Ternary Operator in Python The ternary operator in Python allows us to perform conditional checks and assign values or perform operations on a single line. It is also known as a conditional expression because it evaluates a condition and returns one value if the condition is True and another if it is False.Basic Example of Te 5 min read Like