Here are the various ways to find the length of a tuple in Python. As a data scientist working with large datasets of US demographics, I often need to determine the size of tuples containing data like state populations, median incomes, and more. In this article, I will explain important methods to accomplish this task with examples.
Find the Length of a Tuple in Python
Before we get into finding the length, let’s review what a tuple is in Python. A tuple is a collection of Python objects that are separated by commas enclosed between parentheses. Tuples are similar to lists, but they are immutable, meaning their contents cannot be changed once defined. Tuples are often used to store related pieces of data.
For example, let’s say we have a tuple containing the populations of some major US cities:
city_populations = ("New York", 8336817, "Los Angeles", 3979576, "Chicago", 2693976)Read Python Set vs Tuple
Use the len() Function to Find Tuple Length
The most simple way to find the length of a tuple in Python is by using the built-in len() function. The len() function in Python returns the number of elements in the tuple.
Here’s an example of using len() to find the length of our city_populations tuple:
city_populations = ("New York", 8336817, "Los Angeles", 3979576, "Chicago", 2693976)
length = len(city_populations)
print(f"The tuple has {length} elements.")Output:
The tuple has 6 elements.I executed the above example code and added the screenshot below.

As we can see, the len() function quickly tells us that the city_populations tuple contains 6 elements.
Check out How to Unpack a Tuple in Python?
Find the Length of Tuple Items
In some cases, you may want to find the length of the individual items within a Python tuple. For example, let’s say we have a tuple of US state names:
states = ("California", "Texas", "Florida", "New York", "Pennsylvania")To find the length of each state name, we can use a combination of len() and a for loop:
states = ("California", "Texas", "Florida", "New York", "Pennsylvania")
for state in states:
print(f"{state} has {len(state)} characters.")Output:
California has 10 characters.
Texas has 5 characters.
Florida has 7 characters.
New York has 8 characters.
Pennsylvania has 12 characters.I executed the above example code and added the screenshot below.

This technique uses the for keyword to create a generator expression that applies len() to each item in the tuple.
Read How to Convert an Array to a Tuple in Python?
Find the Length of the Longest Item in a Tuple
Another common task is finding the length of the longest item in a tuple. We can achieve this by combining len() with the max() function in Python.
Using our states tuple from earlier:
states = ("California", "Texas", "Florida", "New York", "Pennsylvania")
longest_state = max(states, key=len)
print(f"The longest state name is {longest_state} with {len(longest_state)} characters.")Output:
The longest state name is Pennsylvania with 12 characters.I executed the above example code and added the screenshot below.

Here, max() finds the longest string in the tuple, while len() determines its length.
Check out How to Iterate Through Tuples in Python?
Conclusion
In this tutorial, I explained how to find the length of a tuple in Python. I discussed using the len() function to find tuple length, finding the length of the tuple items, and finding the length of the longest item in a tuple.
You may read:
- How to Sort by the Second Element in a Tuple in Python?
- How to Return a Tuple in Python?
- How to Append Elements to a Tuple in Python?

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.