python 之 不同类型对象的内存占用、大小比较

python中的标准数据类型有:整型、长整型(py3已去掉)、浮点型、复数型、布尔型、字符串、列表、元组、字典

常用分类:

1.序列类型(有顺序):字符串、列表、元组;映射类型:字典

2.数字类型:整型、长整型(py3已去掉)、浮点型

操作:

1.取字符串长度用len(strName)

2.取对象占内存大小用getsizeof(objName),具体见:

http://www.cnblogs.com/Lvkun/archive/2012/03/01/python_object_memory_usage.html

3.类型比较大小遵循:CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.(不同类的对象根据类型名称排序(如:int>list),同类但类型不支持普通比较的对象根据地址比较),前提是类型不包含complex附属类型(complex不可以进行比较)。具体见:

https://segmentfault.com/q/1010000005882041

普通类型大小比较:字符串(字符串比大小是从左往右一个一个字符比较,相等就往后比,不相等,谁字符大就返回字符串大,和字符串长度没关系)

比如print '1234' > '13'#false

猜你喜欢

转载自blog.csdn.net/zealice/article/details/79217199