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

相关文章

docker django无法访问redis容器的解决方法

docker django无法访问redis容器的解决方法

docker-compose.yal文件中: redis: image: redis container_name: xdemo.redis ports: - 6...

详解appium+python 启动一个app步骤

详解appium+python 启动一个app步骤

询问度娘搭好appium和python环境,开启移动app自动化的探索(基于Android),首先来记录下如何启动待测的app吧! 如何启动APP?1.获取包名;2.获取launcher...

python TK库简单应用(实时显示子进程输出)

python TK库简单应用(实时显示子进程输出)

本文介绍python TK库简单应用(实时显示子进程输出),分享给大家,具体如下: #!/usr/bin/python3.5 # -*- coding: UTF-8 -*- im...

python logging添加filter教程

例子一 def filter(self, record): """Our custom record filtering logic. Built-in filter...

对python3中, print横向输出的方法详解

Python 2 : print打印的时候,如果结尾有逗号,打出来时候不会换行。但是在python3里面就不行了。 Python3 : 3.0的print最后加个参数end=""就可以了...