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