How to know the Size of an Object in Python

If you want to know the size of objects in Python you can make use of the getsizeof() function from the sys module.

sys.getsizeof(object[, default])

Return the size of an object in bytes.

Read more:

>>> import sys
>>> data_list = [10,20,30,40,60,80]
>>> sys.getsizeof(data_list)
>>> city = "New York"
>>> sys.getsizeof(city)
>>> no = 1
>>> sys.getsizeof(no)
Python Get Size of Objects Examples

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap