python size of object code example

Example 1: size of variable python

import sys
sys.getsizeof(object[, default])
# returns size of object in bytes

Example 2: 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 ##