how to get the ordinal number in list
Chris Angelico
rosuav at gmail.com
Mon Aug 11 19:27:15 EDT 2014
On Tue, Aug 12, 2014 at 12:32 AM, Robin Becker <robin at reportlab.com> wrote:
> Of course Python can be even more confusing so that for example
>
>>>> class NeverEqual(int):
> ... def __new__(cls,v):
> ... self = int.__new__(cls,v)
> ... return self
> ... def __eq__(self,other):
> ... return False
> ...
>>>> a=NeverEqual(1)
>>>> a
> 1
>>>> a==1
> False
>>>> a==a
> False
>>>> not (a != a)
> True
>>>> a!=a
> False
>>>>
>
> so I think that assignment doesn't always make things equal even
> chronologically.
Sure, but at this point you're fiddling with the definition of
equality, and Python has never stopped you from shooting yourself in
the foot :) There are less contrived examples, too, like those
involving floating-point round-off, which basically prove that
Python's equality comparison is not the same as mathematical equality;
but that doesn't stop people from comprehending that "1 + 3 == 2 + 2"
in Python based on their knowledge of mathematics.
ChrisA
More information about the Python-list
mailing list