Find Tuple Length - Python Examples
Length of a Python Tuple denotes the number of items in it.
To get the length of a Tuple in Python, use len()
builtin function. len() returns an integer representing the number of items in this Tuple.
Examples
1. Get the length of a given tuple
In this example, we have a Tuple with three items. When we use len() on the tuple, we should get 3 returned by the len() function.
Python Program
# Take a tuple
tuple1 = ('apple', 'banana', 'cherry')
# Get tuple length
tupleLength = len(tuple1)
# Print the value
print(tupleLength)
Output
3
2. Length of an empty tuple
Empty tuple contains no items, and therefore zero should be returned by len().
Python Program
tuple1 = ()
tupleLength = len(tuple1)
print(tupleLength)
Output
0
Summary
In this Python Examples tutorial, we learned how to get the length of a Python Tuple.