If you want to know the size of objects in Python you can make use of the getsizeof() function from the sys module.
Syntax:sys.getsizeof(object[, default])
Examples:
>>> import sys
>>>
>>> data_list = [10,20,30,40,60,80]
>>>
>>> sys.getsizeof(data_list)
104
>>>
>>> city = "New York"
>>>
>>> sys.getsizeof(city)
57
>>>
>>> no = 1
>>>
>>> sys.getsizeof(no)
28

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!