本文介绍了真实情况如何<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__.
更多推荐
真实情况如何<2实施?
发布评论