Python Practice › sys Module Programs › Program 12
Size of objects
Write a Python program that compares the memory size of a few objects.
Output
True True
Approach
sys.getsizeof.
Solution
import sys small, big = [], list(range(1000))print(sys.getsizeof(small) < sys.getsizeof(big))print(sys.getsizeof("") < sys.getsizeof("python"))Output
True True
Learn the concept
New to this topic? Read the lesson, then come back.