How to know bytes size of python object like arrays and dictionaries? – The simple way

There’s:

>>> import sys
>>> sys.getsizeof([1,2, 3])
96
>>> a = []
>>> sys.getsizeof(a)
72
>>> a = [1]
>>> sys.getsizeof(a)
80

But I wouldn’t say it’s that reliable, as Python has overhead for each object, and there are objects that contain nothing but references to other objects, so it’s not quite the same as in C and other languages.

Have a read of the docs on sys.getsizeof and go from there I guess.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)