Python Tuple - Len Function

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:

# 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:

Total number of elements present in the tuple:

7


Copyright 2022 © pythontic.com