How do I determine the size of an object in Python?

前端 未结 13 1463
半阙折子戏
半阙折子戏 2020-11-21 21:53

I want to know how to get size of objects like a string, integer, etc. in Python.

Related question: How many bytes per element are there in a Python list (tuple)?

相关标签:
13条回答
  • 2020-11-21 22:57

    Here is a quick script I wrote based on the previous answers to list sizes of all variables

    for i in dir():
        print (i, sys.getsizeof(eval(i)) )
    
    0 讨论(0)
提交回复
热议问题