How to get the memory size of a tuple in Python

2 Answers

0 votes
tpl = ('python', 'java', 2022, 'c++', 3.14)

size = tpl.__sizeof__()

print(size, "Bytes")



'''
run:

64 Bytes

'''

 



answered Nov 26, 2022 by avibootz
0 votes
import sys

tpl = ('python', 'java', 2022, 'c++', 3.14)

size = sys.getsizeof(tpl)

print(size, "Bytes")

# getsizeof() calls __sizeof__ and adds an additional garbage collector overhead 
# if the object is managed by the garbage collector



'''
run:

80 Bytes

'''

 



answered Nov 26, 2022 by avibootz

Related questions

1 answer 165 views
1 answer 86 views
1 answer 126 views
2 answers 415 views
1 answer 124 views
124 views asked Nov 30, 2023 by avibootz
...