Example:
tuple = ("python", "includehelp", 43, 54.23)
Find the size of a tuple using len() method
We can find the size (the number of elements present) for a tuple easily using the built-in method present in the Python's library for collection, the len() method.
Syntax:
len(tuple_name)
The method accepts a collection as input and returns the number of elements present in it.
Program to find the size of tuple in Python
Output:
Find the size occupied by the tuple in memory
In Python, we can also find the total amount of memory occupied by the tuple in Pusing the __sizeof__() method or getsizeof() method.
Find the size of a tuple using __sizeof__() method
__sizeof__() is a built0in method in python which is used to find the total memory space occupied by the object.
Syntax:
It returns the space occupied by the object in bytes.
Program to find the size of tuple
Output:
Find the size of a tuple using getsizeof() method
Another method to find the amount of memory occupied by the object in Python is using getsizeof() method. The method is present in the sys module in Python.
Imported using: import sys
Syntax:
Program to find the size of tuple in Python
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer