python 基本数据类型占用内存空间大小的实例

yipeiwu_com5年前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 

以上这篇python 基本数据类型占用内存空间大小的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Atom的python插件和常用插件说明

python: simplified-chinese-menu:中文汉化(英文差的) 代码高亮:Atom自带 自动补全:autocomplete-python 语法检查:linter-f...

OPENCV去除小连通区域,去除孔洞的实例讲解

OPENCV去除小连通区域,去除孔洞的实例讲解

一、对于二值图,0代表黑色,255代表白色。去除小连通区域与孔洞,小连通区域用8邻域,孔洞用4邻域。 函数名字为:void RemoveSmallRegion(Mat &Src, Ma...

Python+Django在windows下的开发环境配置图解

Python+Django在windows下的开发环境配置图解

1         安装配置开发环境 1.1   准备安装 下载以下软件 Eclipse for...

详解django三种文件下载方式

一、概述 在实际的项目中很多时候需要用到下载功能,如导excel、pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍djang...

Python编写的com组件发生R6034错误的原因与解决办法

解决该问题的方法可以为调用本程序的exe文件建立一个合适的manifest文件,指定正确的msvcr90.dll版本即可,具体可参照/post/35219.htm ps:可以使用mt.e...