How to check the memory size of a variable in Python

Introduction

I will write a memorandum on how to check the memory size of a variable in Python.

getsizeof function of sys module

Returns the size of the argument in bytes.

>>> import sys
>>> x1 = [1, 2, 3, 4, 5]
>>> sys.getsizeof(x1)
104
>>> x2 = ['a', 'b', 'c']
>>> sys.getsizeof(x2)
88

References

-29.1.sys — System Parameters and Functions Python 3.6.1 Documentation

Recommended Posts

How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
I made a program to check the size of a file in Python
How to check in Python if one of the elements of a list is in another list
How to determine the existence of a selenium element in Python
How to embed a variable in a python string
How to get the variable name itself in python
How to get the number of digits in Python
Python Note: The mystery of assigning a variable to a variable
How to pass the execution result of a shell command in a list in Python
How to mention a user group in slack notification, how to check the id of the user group
How to get a list of files in the same directory with python
[python] How to check if the Key exists in the dictionary
How to use the __call__ method in a Python class
How to develop in a virtual environment of Python [Memo]
How to get the last (last) value in a list in Python
How to get a list of built-in exceptions in python
How to check the version of Django
How to get a stacktrace in python
How to check opencv version in python
[sh] How to store the command execution result in a variable
[Introduction to Python] How to use the in operator in a for statement?
[TensorFlow 2] How to check the contents of Tensor in graph mode
How to find the memory address of a Pandas dataframe value
How to get the vertex coordinates of a feature in ArcPy
How to quickly count the frequency of appearance of characters from a character string in Python?
How to check if the contents of the dictionary are the same in Python by hash value
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to use the C library in Python
How to clear tuples in a list (Python)
Summary of how to import files in Python 3
Get the caller of a function in Python
How to implement shared memory in Python (mmap.mmap)
How to create a JSON file in Python
Make a copy of the list in Python
Summary of how to use MNIST in Python
How to notify a Discord channel in Python
How to get the files in the [Python] folder
Output in the form of a python array
[Python] How to draw a histogram in Matplotlib
[Python] How to specify the window display position and size of matplotlib
How to send a visualization image of data created in Python to Typetalk
[Python] How to put any number of standard inputs in a list
Check the in-memory bytes of a floating point number float in Python
[Introduction to Python] How to sort the contents of a list efficiently with list sort
Test & Debug Tips: Create a file of the specified size in Python
How to format a list of dictionaries (or instances) well in Python
How to sort by specifying a column in the Python Numpy array.
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
Various ways to read the last line of a csv file in Python
Check if the string is a number in python
Easy way to check the source of Python modules
How to convert / restore a string with [] in python
I want to embed a variable in a Python string
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
How to know the current directory in Python in Blender
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
[Python] How to expand variables in a character string
How to count the number of elements in Django and output to a template
How to write a list / dictionary type of Python3
[python] How to sort by the Nth Mth element of a multidimensional array