जब टपल के आकार का पता लगाना आवश्यक हो, तो 'आकार' विधि का उपयोग किया जा सकता है।
नीचे उसी का प्रदर्शन है -
उदाहरण
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") आउटपुट
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 स्पष्टीकरण
-
आवश्यक पैकेज आयात किए जाते हैं।
-
टुपल्स परिभाषित हैं, और कंसोल पर प्रदर्शित होते हैं।
-
प्रत्येक टपल पर 'आकार' विधि को कॉल किया जाता है और लंबाई को कंसोल पर आउटपुट के रूप में प्रदर्शित किया जाता है।