How do I determine the size of an object in Python?
You can use the sys.getsizeof()
function to determine the size of an object in bytes. Here is an example:
import sys
my_list = [1, 2, 3, 4, 5]
print(sys.getsizeof(my_list))
Watch a video course
Python - The Practical Guide
This will output the size of the my_list
object in bytes. Please be aware that getsizeof() function will give the size of the object in memory and not the actual object size on disk.