[BangPypers] Python comparisons

Gora Mohanty gora at mimirtech.com
Sat Dec 5 09:42:34 EST 2015


On 5 December 2015 at 12:56, Noufal Ibrahim KV <noufal at nibrahim.net.in> wrote:
>
>
> So I came across this today..
>
> >>> class Number(object):
> ...    def __init__(self, n):
> ...       self.n = n
> ...
> >>> m = Number(10)
> >>> n = Number(5)
> >>>
> >>> m < n
> True
>
> This is documented like so
>
> > If no __cmp__(), __eq__() or __ne__() operation is defined, class
> > instances are compared by object identity (“address”).
>
> over here https://docs.python.org/2/reference/datamodel.html#object.__cmp__

Maybe because that was the historical way that C did it? I agree that
the Python 3 exception makes more sense.

Regards,
Gora


More information about the BangPypers mailing list