Python 不同对象比较大小示例探讨

yipeiwu_com6年前Python基础

万恶的源泉:

Fireboo的疑问(当然 lambda 本身写的就有问题):

>>> filter( lambda x: x > 2, [ 1, [ 1, 2, 3 ], 2, 3 ] ) 
[[1, 2, 3], 3]

?:

>>> 1 < [ 1 ] 
True 
>>> int < list 
True 
>>> dict < int < list 
True
>>> int < map 
False

后来几经周折,和 Fireboo 讨论了下,是

1.不同对象比较(除了 number 之外),是按照 type names 比较,

2.当相同类型对象不支持适当比较的时候,采用 address 比较

3.list 与 list, tuple 与 tuple 采用字典序比较

>>> x = 1 
>>> y = [ 1 ] 
>>> type( x ) 
<type 'int'> 
>>> type( y ) 
<type 'list'> 
>>> x < y 
True
>>> type( int ) 
<type 'type'> 
>>> type( list ) 
<type 'type'> 
>>> id( int ) 
505552912 
>>> id( list ) 
505555336 
>>> int < list 
True
>>> type( map ) 
<type 'builtin_function_or_method'> 
>>> type( list ) 
<type 'type'> 
>>> map < list 
True

相关文章

python dataframe向下向上填充,fillna和ffill的方法

首先新建一个dataframe: In[8]: df = pd.DataFrame({'name':list('ABCDA'),'house':[1,1,2,3,3],'date':...

Python中用Decorator来简化元编程的教程

少劳多得 Decorator 与 Python 之前引入的元编程抽象有着某些共同之处:即使没有这些技术,您也一样可以实现它们所提供的功能。正如 Michele Simionato 和我在...

python fabric使用笔记

fabric title是开发,但是同时要干开发测试还有运维的活……为毛 task*3 不是 salary * 3 (o(╯□╰)o) 近期接手越来越多的东西,发布和运维的工作相当机械,...

python实现简单图片物体标注工具

python实现简单图片物体标注工具

本文实例为大家分享了python实现简单图片物体标注工具的具体代码,供大家参考,具体内容如下 # coding: utf-8 """ 物体检测标注小工具 基本思路: 对要标注的图...

Python模拟简单电梯调度算法示例

Python模拟简单电梯调度算法示例

本文实例讲述了Python模拟简单电梯调度算法。分享给大家供大家参考,具体如下: 经常在公司坐电梯,由于楼层较高,是双联装的电梯,但是经常等电梯很久,经常有人骂写电梯调度算法的。回来闲来...