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

yipeiwu_com5年前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实现控制COM口的示例

使用RS232串口线或者是RS232转USB的这一类的接口,会需要com口作为接口来进行输入输出调式, 写了个脚本来控制COM口,用到了Python内建的serial库 代码如下:...

如何使用python进行pdf文件分割

这篇文章主要介绍了如何使用python进行pdf文件分割,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 代码如下 import o...

python判断windows系统是32位还是64位的方法

本文实例讲述了python判断windows系统是32位还是64位的方法。分享给大家供大家参考。具体分析如下: 通常64的windows系统program files文件夹(用来安装应用...

Python如何实现动态数组

Python如何实现动态数组

Python序列类型 在本博客中,我们将学习探讨Python的各种“序列”类,内置的三大常用数据结构——列表类(list)、元组类(tuple)和字符串类(str)。 不知道你发现没有...

python代码编写计算器小程序

本文实例为大家分享了python计算器小程序的具体代码,供大家参考,具体内容如下 import tkinter import tkinter.messagebox import ma...