sys.getsizeof() >>> help(sys.getsizeof)Help on built-in function getsizeof in module sys: getsizeof(...) getsizeof(object, default) -> int Return the size of object in bytes.说明:返回整数,单位是字节.…
from sys import getsizeof class A(object): pass class B: pass for x in (None, 1, 1L, 1.2, 'c', [], (), {}, set(), B, B(), A, A()): print "{0:20s}\t{1:d}".format(type(x).__name__, sys.getsizeof(x)) NoneType 16 int 24 long 28 float 24 str 34 list…