Find the Length of Tuple in Python : 3 Steps Only

Find the Length of Tuple in Python

Tuple is a data structure that allows you to store multiple values in a single variable. All the elements inside it are ordered and unchangeable like a list. Let’s say you have a tuple and want to find its length then you can easily find using the len() function. In this tutorial, you will know how to find the length of a tuple in python through steps.

Steps to find the length of a tuple in python

Let’s know all the steps that you will follow to find the length of a tuple in python.

Step 1: Create a sample tuple

The first step is to create a dummy tuple that will be used to find its length in the next step. You can create a tuple using the square brackets. Use the below line of code to create it.

sample_tuple = (10, 20, 30, "Data", "Science","Learner")
print(sample_tuple)

Output

sample tuple to find its length
sample tuple to find its length

Step 2: Find the length of a tuple in python using len() function

After the creation of the tuple let’s find the length of the tuple using the len() function. But before that let us know the syntax of the len() function.

len(object)

Here the argument is the object that will be a collection like a list, tuple, etc. It will return the total number of elements present in the collection.

To find the length of the tuple you have to just pass your tuple inside the len() object.

Execute the below lines of code to find the len() of the tuple.

len(sample_tuple )

Step 3: Print the length of the tuple

After implementing the second step let’s print out the length of the tuple. To do so you will use the print() function.

print(len(sample_tuple))

Full Code

sample_tuple = (10, 20, 30, "Data", "Science","Learner")
print(len(sample_tuple))

Output

print out the length of tuple
print out the length of tuple

Conclusion

You can easily find the length of a tuple using the len() function. This function also allows you to check whether the tuple is empty or not if the return value is 0. These are steps to find the length of a tuple.

I hope you must have understood how to use it. If you have any queries then you can contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner