I was experimenting with the built-in methods __lt__()
, __gt__()
and __eq__()
.
When I tried to do the operation directly, like
2.__lt__(5)
, it gave output as invalid syntax instead I was expecting it to give as True
.
when these values are being referenced through name bindings, it works fine, Like above
a = 2
b = 5
a.__lt__(b)
gives True
as output, which is expected.
when we check the type of the object, in both scenarios it is the same as <class 'int'>
type(2)
<class 'int'>
type(a)
<class 'int'>
why does it differ when the same type of objects are being passed to the built-in methods?