How Can We Help?
While working with tuples in Python, it’s a common task often requested to get the tuple’s size or length, and here in this article, we will explain it by practical example.
How to find the length of a tuple in Python? To find the size of a tuple in Python, We use the len() function in Python. The length function is used to find the length of a tuple. It’s calculating the size of a tuple; It takes one parameter, it’s a tuple in our case and returns a total length of a tuple by counting its number of elements.
Python Tuple Length Syntax:
len(tuple_variable_name)
Input Parameters:
- tuple_variable_name: the tuple name which needs to get the length of the element inside.
Python Tuple Length Example
alphabet=('a','b','c','d','e')
# length of tuple or size of a tuple
print('length of tuple:',len(alphabet))
Output
length of tuple: 5
In the above example, the tuple variable ‘alphabet’ has five values, i.e., its length is 5, which we got by len(alphabet), so the output is “5”.
In Python, the len() function is also used to get the size of a list like a tuple. Check this article for how to find the length of a list in Python to see how by example.
In this tutorial, you have learned How to get the length or size of tuple in Python.
Hopefully, it was clear and concise.
If you have an inquiry or doubt, don’t hesitate to leave them in a comment. We are waiting for your valuable feedback.
Similar Python Tuple Length Function:
- min(tuple): It returns a minimum value of the tuple.
- type(tuple) : It returns a maximum value of tuple.
- len(tuple): It returns the type of tuple if the passed variable is a tuple.
- tuple(seq) : It converts a sequence/string into tuple.
- del(tuple) : It deletes whole tuple or individual tuple element or all elements of tuple.
Related Articles
Python Tuple – Mastering By Practical Examples (Comprehensive Guide)
Python Tutorials List:
- Python tutorials list: access all python tutorials.