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

相关文章

Python实现检测代理IP是否可以翻墙

那堵墙着实可恨!身处IT这个圈子,经常需要用gg查资料(你也可以用来访问1024,^_^...)。当然,你也可以用百度。其实也不是我不爱用百度,是有缘由的,且听我细细道来。有一次闲得蛋疼...

Python中print函数简单使用总结

Python中print函数简单使用总结

print函数是Python的入门,每一个学习python的人都绕不开这个函数,下面介绍一下这个函数的用法。 打开电脑,选择python软件,下面选择python 3.7为例进行介绍,点...

Ruby元编程基础学习笔记整理

笔记一: 代码中包含变量,类和方法,统称为语言构建(language construct)。 # test.rb class Greeting def initialize(te...

Python简单获取自身外网IP的方法

本文实例讲述了Python简单获取自身外网IP的方法。分享给大家供大家参考,具体如下: #encoding=utf-8 #author: walker #date: 2016-03-...

Python使用win32 COM实现Excel的写入与保存功能示例

Python使用win32 COM实现Excel的写入与保存功能示例

本文实例讲述了Python使用win32 COM实现Excel的写入与保存功能。分享给大家供大家参考,具体如下: 很久之前通过东拼西凑实现过使用Python通过win32 COM实现wo...