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设计模式之原型模式实例详解

Python设计模式之原型模式实例详解

本文实例讲述了Python设计模式之原型模式。分享给大家供大家参考,具体如下: 原型模式(Prototype Pattern):用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的...

Django集成CAS单点登录的方法示例

Django集成CAS单点登录的方法示例

CAS 全称集中式认证服务(Central Authentication Service),是实现单点登录(SSO)的一中手段。 CAS 的通讯流程图如下(图片来自Google图库):...

python各种语言间时间的转化实现代码

一 基本知识 millisecond 毫秒 microsecond 微秒 nanosecond 纳秒 1秒=1000毫秒 1毫秒=1000微秒 1微秒=1000纳秒 二 perl pe...

通过实例了解python property属性

这篇文章主要介绍了通过实例了解python property属性,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1. 什么是prope...

简单谈谈Python中函数的可变参数

前言 在Python中定义函数,可以用必选参数、默认参数、可变参数和关键字参数,这4种参数都可以一起使用,或者只用其中某些,但是请注意,参数定义的顺序必须是:必选参数、默认参数、可变参...