真实情况如何<2实施?

编程入门 行业动态 更新时间:2024-10-08 00:23:26
本文介绍了真实情况如何<2实施?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

它不是直接在bool上实现的.

It's not implemented directly on bool.

>>> True.__lt__(2) AttributeError: 'bool' object has no attribute '__lt__'

而且显然也没有在 int 上实现:

And it's apparently not implemented on int either:

>>> super(bool, True).__lt__(2) AttributeError: 'super' object has no attribute '__lt__'

没有用于 2 的 __ lt __ 反射版本来控制操作,并且由于 int 类型不是的子类bool 永远无法正常工作.

There is no reflected version of __lt__ for 2 to control the operation, and since int type is not a subclass of bool that would never work anyway.

Python 3的行为符合预期:

Python 3 behaves as expected:

>>> True.__lt__(2) True

所以, True<怎么样?2 是在Python 2中实现的吗?

So, how is True < 2 implemented in Python 2?

推荐答案

您没有找到 super(bool,True).__lt __ ,因为 int 使用旧版 __ cmp __ 方法,而不是在Python 2上进行丰富的比较.它是 int .__ cmp __ .

You didn't find super(bool, True).__lt__ because int uses the legacy __cmp__ method instead of rich comparisons on Python 2. It's int.__cmp__.

更多推荐

真实情况如何&lt;2实施?

本文发布于:2023-11-23 07:02:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:真实情况   amp   lt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!