Check the Memory Consumed By Variables in Python

We can check the memory consumed by variables in python using the sys module and getsizeof() function.

sys is a Python module and which provides us a lot of various in-built functions and variables and we can use these functions and variables in the Python runtime environment to make change something.

And getsizeof() function from the sys module to use for get the size of variables or objects in bytes.

Let’s see the example.

In the above example, we first import the sys module. Then declare the python variables to check the memory size consumed by them.

Finally, we print the memory size with getsizeof() function.

Being Tricky 😉

Leave a Reply

Your email address will not be published. Required fields are marked *