Python Tuple - len function

To find the the length of a tuple in python use the len function by passing the tuple object inside the function

Tuple Updated 18 Sep 2016 1 min read

Function Name

len

Function Signature

len(tuple_in)

Function Overview

  • The len() function returns the total number of elements present in a Python tuple object.
  • The len() function differs from the count() method of the tuple where the count() method returns the number of elements with a specific value.

Parameters

tuple_in: The tuple object in which the total number of elements present, needs to be found.

Return Value

An integer value specifying the number of elements in a Python tuple object.

Example

python
# Example Python program that creates

            # a tuple and returns the number of elements

            # present in it

rainbowColors   = ('Violet', 'Indigo', 'Blue', 'Green', 'Yellow', 'Orange', 'Red')

            totalElems      = len(rainbowColors)

            print("Total number of elements present in the tuple:")

            print(totalElems)

Output

Output
Total number of elements present in the tuple:

7