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

作者:whsnow 时间:2023-06-11 01:13:32 

万恶的源泉:

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
标签:对象,大小
0
投稿

猜你喜欢

  • PHP实现手机归属地查询API接口实现代码

    2023-11-14 09:10:33
  • 手写一个python迭代器过程详解

    2021-06-29 07:45:23
  • Python利用zhdate模块实现农历日期处理

    2023-03-07 22:10:20
  • python Tkinter的图片刷新实例

    2023-10-31 04:32:24
  • Python虚拟环境venv用法详解

    2023-10-26 12:37:12
  • 对pyqt5中QTabWidget的相关操作详解

    2021-12-15 16:54:54
  • Keras 多次加载model出错的解决方案

    2023-11-01 20:52:35
  • flask-script模块的具体使用

    2022-04-08 10:53:34
  • python如何获取apk的packagename和activity

    2023-07-11 20:50:19
  • Python pandas对excel的操作实现示例

    2023-09-25 18:24:13
  • jQuerify书签

    2008-06-16 12:16:00
  • 你需要知道的CSS3 动画技术[译]

    2009-12-30 17:02:00
  • Python实现字符串格式化的方法小结

    2022-08-14 11:04:02
  • 如何编写一个高效的国税系统通讯录数据库?

    2009-11-07 18:53:00
  • SQL Server中导入导出数据的三种方式

    2008-11-28 15:53:00
  • Python实现对excel文件列表值进行统计的方法

    2022-08-08 17:42:23
  • ASP 自动采集实现代码

    2011-03-07 11:17:00
  • Ajax实现搜索框提示功能

    2023-09-11 20:51:21
  • Python字符串中删除特定字符的方法

    2023-07-25 18:58:54
  • 让你Python到很爽的加速递归函数的装饰器

    2022-10-23 13:04:47
  • asp之家 网络编程 m.aspxhome.com