python 基本数据类型占用内存空间大小的实例
python中基本数据类型和其他的语言占用的内存空间大小有很大差别
import sys a = 100 b = True c = 100L d = 1.1 e ="" f = [] g =() h = {} i = set([]) print " %s size is %d "%(type(a),sys.getsizeof(a)) print " %s size is %d "%(type(b),sys.getsizeof(b)) print " %s size is %d "%(type(c),sys.getsizeof(c)) print " %s size is %d "%(type(d),sys.getsizeof(d)) print " %s size is %d "%(type(e),sys.getsizeof(e)) print " %s size is %d "%(type(f),sys.getsizeof(f)) print " %s size is %d "%(type(g),sys.getsizeof(g)) print " %s size is %d "%(type(h),sys.getsizeof(h)) print " %s size is %d "%(type(i),sys.getsizeof(i)) <type 'int'> size is 12 <type 'bool'> size is 12 <type 'long'> size is 14 <type 'float'> size is 16 <type 'str'> size is 21 <type 'list'> size is 36 <type 'tuple'> size is 28 <type 'dict'> size is 140 <type 'set'> size is 116
相关推荐
FlySky 2020-11-02
逍遥友 2020-10-26
taiyangshenniao 2020-10-05
flycony 2020-09-23
jacktangj 2020-09-18
YENCSDN 2020-09-15
lsjweiyi 2020-09-14
digwtx 2020-09-14
拾毅者 2020-09-14
zlxcsdn 2020-09-13
weiiron 2020-08-17
amazingbo 2020-08-16
郗瑞强 2020-08-16
lispython 2020-08-16
fengling 2020-08-15
xiesheng 2020-08-02
葫芦小金刚 2020-07-28
StevenSun空间 2020-07-26