Find Length of Tuple or Get Items Size Using Python

In this tutorial, learn how to find length of tuple in Python. The short answer is to use the Python len() to get the length of tuple variable. The length of the tuple can also be found using the for loop.

The len() function is the easiest way to know the size of any variable using Python. You may also like to read how to find the size of list variable using Python.

Check the below examples given with the two ways to find the length. So, let’s start learning each section one by one with the examples given here.

Method 1: How to Find Length of Tuple Using Python len()

If you want to find the length of tuple variable, you have to use the Python len() function. The function takes a single argument which is the tuple variable. However, you can find the length of any Python variable by using this function.

See the example below with the single tuple variable. The len() function contains the tuple variable as the argument.



There are 6 elements in the tuple variable. The above example prints the size of the tuple as 6. No matter whether the variable contains the string or integer. The len() count both the string and the integer element of the tuple.

Method 2: Get Size of Tuple Using For Loop in Python

In addition to the above method, you can also get the length of the tuple variable using the loop. To find the length of the tuple variable, you have to use the for loop with the method as given in the example below.

To perform this task using the for loop, you have to use initiate a variable with zero(0). After that, increment the variable with 1 as given below.



The above example prints the size of the tuple variable using the for loop of Python. The print function contains in the above example is outside of the for the loop.

Hope, you like this post of how to get the size of tuple variable using Python. If you have any query regarding the tutorial, please comment below.

W3resource to Calculate Tuple Size in Python

Also tell me, which method you are using to find the size of the tuple variable.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.