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

相关文章

Django后端发送小程序微信模板消息示例(服务通知)

Django后端发送小程序微信模板消息示例(服务通知)

模板消息 官方文档:https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/template-mess...

Python在图片中插入大量文字并且自动换行

Python在图片中插入大量文字并且自动换行

问题 如何在图片中插入大量文字并且自动换行 效果 原始图 效果图 注明 若需要写入中文请使用中文字体 实现方式 from PIL import Image, ImageDraw,...

python处理圆角图片、圆形图片的例子

python处理圆角图片、圆形图片的例子

效果图如下: 图1(头像图片剪成圆形的,其他为透明) 图2(给图片的4个角加椭圆) 以前没处理过,处理起来真是有点费力呀。 用到的模块:复制代码 代码如下:import os, mat...

python如何在终端里面显示一张图片

python如何在终端里面显示一张图片

Linux终端里面可谓是奇妙无限,很多优秀的软件都诞生在终端里面。相较之下,Windows本身的理念和Linux就不一致,所以,你懂得。 下面,我们不妨先思考一下,如何在终端里面显示一...

python语言使用技巧分享

python语言使用技巧分享

一 在写之前 最好指定python的路径: #!/usr/bin/python python 在linux中需要添加编码方式:以免出现中文乱码 # -*- coding: UTF-8...