1. from sys import getsizeof
    2. class B:
    3. pass
    4. # 不同数据类型占用内存大小
    5. for x in (None, 1, 1.3, 'a', {}, [], (), set(), B, B()):
    6. print('{0:10}\t{1:}字节'.format(type(x).__name__, getsizeof(x)))
    7. -------------------------------------------------------------------------
    8. #NoneType 16字节
    9. #int 28字节
    10. #float 24字节
    11. #str 50字节
    12. #dict 240字节
    13. #list 64字节
    14. #tuple 48字节
    15. #set 224字节
    16. #type 1056字节
    17. #B 56字节