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、tensorflow、opencv、pyqt5实现人脸实时签到系统

利用python、tensorflow、opencv、pyqt5实现人脸实时签到系统

基于python opencv人脸识别的签到系统前言先看下效果实现的功能开始准备页面的构建功能实现代码部分总结 前言 一个基于opencv人脸识别和TensorFlow进行模型训练的人脸...

python自定义函数实现最大值的输出方法

python中内置的max()函数用来得到最大值,通过冒泡排序也可以。 #!/usr/bin/python def getMax(arr): for i in range(0...

Python中用函数作为返回值和实现闭包的教程

函数作为返回值 高阶函数除了可以接受函数作为参数外,还可以把函数作为结果值返回。 我们来实现一个可变参数的求和。通常情况下,求和的函数是这样定义的: def calc_sum(*ar...

python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)

复制代码 代码如下:#-*- coding:utf-8 -*- from win32com.client import Dispatch import time def start_of...

使用Python下的XSLT API进行web开发的简单教程

使用Python下的XSLT API进行web开发的简单教程

Kafka 样式的 soap 端点 Christopher Dix 所开发的“Kafka — XSL SOAP 工具箱”(请参阅 参考资料)是一种用于构造 SOAP 端点的 XSLT 框...