010 python语法_函数 sys.getsizeof()


 

 

'''
时间:2018/10/30
目的: 显示数据类型大小 
'''

 

# coding:utf-8
import sys

# 数据类型
int = 100
bool = True
float = 1.1
str =""
list = []
tuple =()
dict = {}
set = set([])


# 显示大小
print("%s size is %d" %(type(int), sys.getsizeof(int)))
print("%s size is %d" %(type(bool), sys.getsizeof(bool)))
print("%s size is %d" %(type(float), sys.getsizeof(float)))
print("%s size is %d" %(type(str), sys.getsizeof(str)))
print("%s size is %d" %(type(list), sys.getsizeof(list)))
print("%s size is %d" %(type(tuple), sys.getsizeof(tuple)))
print("%s size is %d" %(type(dict), sys.getsizeof(dict)))
print("%s size is %d" %(type(set), sys.getsizeof(set)))
<class 'int'>
<class 'int'> size is 14
<class 'bool'> size is 14
<class 'float'> size is 16
<class 'str'> size is 25
<class 'list'> size is 36
<class 'tuple'> size is 28
<class 'dict'> size is 136
<class 'set'> size is 116

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM