Skip to content

How to get the size of an object in Python?

import sys
object = set()

print(sys.getsizeof(object))
##### will get 216 possibly based on version 3.9 ###

###  use different objects like list(), dict(), str(), int(), float(), etc..###
### for getting to know size of each objects and use the most appropriate ###
## particularly set and dict will seem to not change in size even after ##
## adding lots of values but they are just so huge, only use them to store ##
## large values ##
See also  How to modulus in Python?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.