It's not implemented directly on bool.
>>> True.__lt__(2) AttributeError: 'bool' object has no attribute '__lt__'
And it's apparently not implemented on int
either:
>>> super(bool, True).__lt__(2) AttributeError: 'super' object has no attribute '__lt__'
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 behaves as expected:
>>> True.__lt__(2) True
So, how is True < 2
implemented in Python 2?
The implementation methodology is the method by which the projects are technically and operationally implemented in the field, most often by using contractors or subcontractors. Typical implementation models are Energy Performance Contracting, Energy Supply Contracting and Separate Contractor Based.
True
is equal to 1 in Python (which is why it's less than 2) and bool
is a subclass of int
: basically, False
and True
are 0 and 1 with funky repr()
s.
As to how comparison is implemented on integers, Python uses __cmp__()
, which is the old-school way of writing comparisons in Python. (Python 3 doesn't support __cmp__()
, which is why it's implemented as __lt__()
there.) See https://docs.python.org/2/reference/datamodel.html#object.__cmp__
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With