×

Python Tuple count() Method

Python Tuple count() Method

The tuple.count() method in Python returns the number of times a specified value appears in the tuple.

Syntax

tuple.count(value)

Parameter

value- This parameter represents the element to search in the tuple

Return

This method returns the number of occurrences of a specified element in the tuple.

Example 1

 # the Python program expalining
 # the tuple.count() method
 # initializing the tuple values
 tupleVal = (1, 2, 3,4,5, 7, 8, 7, 5, 5, 6, 4, 4)
 print("Tuple:",tupleVal)
 # counting the number os occureneces of 4 in the given tuple
 occureneces = tupleVal.count(4)
 # printing the returned value
 print("The item '4' occured",occureneces,"times")) 

Output

Tuple: (1, 2, 3, 4, 5, 7, 8, 7, 5, 5, 6, 4, 4)
The item '4' occured 3 times

Example 2

 # Python program explaining
 # the tuple.count() method
 # initializing a random tuple
 Tupleval = ('a', ('b', 'c'), ('a', 'b'), [8, 4],[8,4])
 # counting the occurences of item ('b', 'c')
 countVal = Tupleval.count(('b', 'c'))
 # printing the count value
 print("The count of ('b', 'c') is:", countVal)
 # count element [3, 4]
 countVal = Tupleval.count([8, 4])
 # printing the count value
 print("The count of [8, 4] is:", countVal) 

Output

The count of ('b', 'c') is: 1
The count of [8, 4] is: 2

Example 3

 # Python program explaining
 # the tuple.count() method
 # initializing a random vowels tuple
 vowels = ('a', 'i', 'o', 'i', 'e', 'i', 'u')
 # paasing an element that is not present in the tuple
 count = vowels.count('z')
 # will return 0 as z is not present in the tuple
 print('The count of z is:', count) 

Output

The count of i is: 0

Related Topics

ER diagram of the Bank Management System in python

What is an ER diagram? The full form of the ER diagram is the Entity Relationship diagram. This diagram is used in database management systems to have a rough idea of...

3 minutes read.

Android apps for coding in python

Nowadays, it is the generation of smartphones. The world can be seen and acknowledged with a single click on your mobile phone. Everyone uses mobile phones to do any work,...

9 minutes read.

Python Identifiers

Identifiers in Python User-defined names are identifiers in Python that are used to name variables, functions, classes, modules, and other things. You can create Python identifiers using these rules: As an identifier...

4 minutes read.

Fsolve in Python

Python Programming Language Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

Python Tutorial

Python tutorial is a widely used programming language which helps beginners and professionals to understand the basics of Python programming easily. Python is a high-level, easy, interpreted, general-purpose, and dynamic programming...

19 minutes read.

How to Reverse a number in Python?

In Python, conditional statements can be combined with the list() method, slice() method, recursion() method, and other predefined techniques to generate reverse logical functions. The reverse() method is the most...

7 minutes read.

How to Convert String to List In Python?

How to Convert String to List In Python? We all are familiar with what strings and lists are, let us have a quick revision on them- Strings are a sequence of characters...

4 minutes read.

Best Database in Python

In this tutorial, Firstly, we will understand what the term database means. Further, we will see the various databases supported in Python and when to use which one. Further, we...

7 minutes read.

Python Kwargs Example

In this article, we'll talk about Python's kwargs notion. In Python, kwargs has two stars and passes a variable number of keyworded argument lists to the function, whereas args has...

5 minutes read.

How to write a program in python?

How to write a program in python? In python, writing programs is not a big deal. What we need to work on is our logic and some basic rules of this...

4 minutes read.

Why learn Python?

All things considered, learning python would be extraordinary, it'll acquaint you with the universe of dynamic programming dialects, if you're somebody who has had a semester of involvement with C. Python...

4 minutes read.

How to uninstall python

To un-install Python, we need to follow different procedures in different operating systems. In this article, we will discuss the un-installation process of Python in Windows, Mac, and Linux operating...

4 minutes read.

Magento 2 Site optimization

Magento 2 Site optimization Magento 2 is a CMS, commonly referred to as Intensive efficiency. Improving the speed and reliability of your Magento 2 app helps clients to achieve a better user experience while...

2 minutes read.

Poolmanager in Python

Python: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

4 minutes read.

Python Program to Find the Greatest Among Three Numbers

Python Program to find the greatest among three numbers We have many approaches to get the largest of three numbers, and here we will discuss a few of them. This python...

2 minutes read.

How to Install Python

Python Installation Guide Step by Step Installing Python is quite simple and easy. In this tutorial, we will show stepwise procedure to install Python and set up the Python environment in different...

2 minutes read.

Python object()

Python object() class The object class in Python is a base for all classes. It returns a new featureless object. Syntax class object Parameter NA Return It returns a new featureless object. Example 1 # Python program explaining # the object()...

1 minute read.

FOO in Python

Python Programming Language: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

3 minutes read.

Python md5() function

Python md5() function The md5() function in PHP calculates the md5 hash of a string. Syntax md5 ( string $str [, bool $raw_output] ) Parameter str(required)- This parameter specifies the string. raw_output(optional)- This parameter specifies a hex or binary output format: TRUE - Raw 16 character binary...

1 minute read.

Python String isspace() method

Python String isspace() method The string.isspace() method returns a Boolean value true if there are only whitespace characters in the given string. This function is used to check if the given...

2 minutes read.