How to find the size of a tuple in Python
In this article, we are going to be learning how to find the size of a tuple in Python.
If you want to learn more about tuple with some examples click here: Tuples in Python
Finding the size of a tuple in Python
Finding the size or length of a tuple is a pretty straightforward process. The size of a tuple represents the number of objects present in the tuple. The syntax used for finding the size is len(). This method returns the number of elements/objects present in the tuple.
Let us see an example,
a = ("codespeedy", "python", "tuple") b = ("programs", "Coding") print("Size of the tuple is", len(a)) print("Size of the tuple is", len(b))
Output:
Size of the tuple is 3 Size of the tuple is 2
Here, we have declared a tuple containing 3 objects. As a result, when we use the len() method, it returns the number of objects present in the tuple i.e 3. the same goes for the next tuple having 2 objects.
Also read:
Leave a Reply