python 基本數(shù)據(jù)類型占用內(nèi)存空間大小的實例
更新時間:2018年06月12日 08:37:44 作者:ben1949
今天小編就為大家分享一篇python 基本數(shù)據(jù)類型占用內(nèi)存空間大小的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
python中基本數(shù)據(jù)類型和其他的語言占用的內(nèi)存空間大小有很大差別
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
以上這篇python 基本數(shù)據(jù)類型占用內(nèi)存空間大小的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
在Windows8上的搭建Python和Django環(huán)境
作為一個.NET程序員,真心不喜歡以及PHP這種松散的語法。有人說,程序員應(yīng)該多學(xué)幾門語言,本想學(xué)習(xí)Java,無奈感覺Java的語法太啰嗦了。很多人都推薦Python,說它的語法簡潔,執(zhí)行效率高。趁這兩天空閑,開始學(xué)習(xí)Python。2014-07-07Pycharm運行時總是跳出Python?Console問題
這篇文章主要介紹了Pycharm運行時總是跳出Python?Console問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04python靜態(tài)web服務(wù)器實現(xiàn)方法及代碼詳解
在本篇內(nèi)容里小編給大家分享了一篇關(guān)于python靜態(tài)web服務(wù)器實現(xiàn)方法,有需要的朋友們可以參考下。2022-11-11python如何遍歷指定路徑下所有文件(按按照時間區(qū)間檢索)
這篇文章主要給大家介紹了關(guān)于python如何遍歷指定路徑下所有文件(按按照時間區(qū)間檢索)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09