
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to Find the size of a Tuple
When it is required to find the size of a tuple, the ‘sizeof’ method can be used.
Below is the demonstration of the same −
Example
import sys tuple_1 = ("A", 1, "B", 2, "C", 3) tuple_2 = ("Java", "Lee", "Code", "Mark", "John") tuple_3 = ((1, "Bill"), ( 2, "Ant"), (3, "Fox"), (4, "Cheetah")) print("The first tuple is :") print(tuple_1) print("The second tuple is :") print(tuple_2) print("The third tuple is :") print(tuple_3) print("Size of first tuple is : " + str(sys.getsizeof(tuple_1)) + " bytes") print("Size of second tuple is : " + str(sys.getsizeof(tuple_2)) + " bytes") print("Size of third tuple is: " + str(sys.getsizeof(tuple_3)) + " bytes")
Output
The first tuple is : ('A', 1, 'B', 2, 'C', 3) The second tuple is : ('Java', 'Lee', 'Code', 'Mark', 'John') The third tuple is : ((1, 'Bill'), (2, 'Ant'), (3, 'Fox'), (4, 'Cheetah')) Size of first tuple is : 96 bytes Size of second tuple is : 88 bytes Size of third tuple is : 80 bytes
Explanation
The required packages are imported.
The tuples are defined, and are displayed on the console.
The ‘sizeof’ method is called on every tuple and the length is displayed as output on the console.
- Related Articles
- Python Program to find the largest element in a tuple
- Python program to find hash from a given tuple
- Python Program to create a Tuple using tuple literal
- Python Program to print elements of a tuple
- Python program to find the size of largest subset of anagram words
- Program to Find Out the Strings of the Same Size in Python
- Program to find tuple with same product in Python
- Program to find latest group of size M using Python
- Program to find out the minimum size of the largest clique in a graph (Python)
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- Python Program to add elements to a Tuple
- Python to Find number of lists in a tuple
- C Program to find size of a File
- Swift Program to Find the Size of Dictionary
- Program to find lexicographically smallest subsequence of size k in Python

Advertisements