Python | Operator.countOf Last Updated : 30 Sep, 2019 Comments Improve Suggest changes 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 Create Quiz Comment G garg_ak0109 Follow 0 Improve G garg_ak0109 Follow 0 Improve Article Tags : Python Python-Operators Python-Built-in-functions Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like