python中基本數據類型和其他的語言占用的內存空間大小有很大差別
import sysa = 100b = Truec = 100Ld = 1.1e =""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
以上這篇python 基本數據類型占用內存空間大小的實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。
新聞熱點
疑難解答