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设计】。

相关文章

手把手教你pycharm专业版安装破解教程(linux版)

手把手教你pycharm专业版安装破解教程(linux版)

1.首先到jetbrains下载专业版 https://www.jetbrains.com/pycharm/download/#section=linux 我这里下载的是pycharm-...

Python简单实现enum功能的方法

本文实例讲述了Python简单实现enum功能的方法。分享给大家供大家参考,具体如下: class Enumerate(object): def __init__(self,na...

Python正规则表达式学习指南

Python正规则表达式学习指南

1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python的一部分。正则表达式是用于处理字符串的强大工具,拥有自己独特的语法以及一个独立的处理引擎,效率上可能不如str自带的...

python生成1行四列全2矩阵的方法

如下所示: print np.ones((1,4))*2 以上这篇python生成1行四列全2矩阵的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听...

python获取网页状态码示例

代码很简单,只需要2行代码就可实现想要的功能,虽然很短,但确实使用,主要使用了requests库。 测试2XX, 3XX, 4XX, 5XX都能准确识别。 复制代码 代码如下:#codi...