Size of objects

Easysys Module Programs · 12 of 20

Write a Python program that compares the memory size of a few objects.

Advertisement
Output
True
True

Approach

  1. sys.getsizeof.

Solution

Python
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.

More sys module programs

← All 20 sys Module Programs

Leave a Comment