Explanation of list reference

Chris Angelico rosuav at gmail.com
Sat Feb 15 03:08:39 CET 2014


On Sat, Feb 15, 2014 at 12:55 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> On Saturday, February 15, 2014 6:27:33 AM UTC+5:30, Chris Angelico wrote:
>> Can you give an example of an ambiguous case? Fundamentally, the 'is'
>> operator tells you whether its two operands are exactly the same
>> object, nothing more and nothing less
>
> Fundamentally your definition above is circular: In effect
> the python expr "a is b" is the same as a is b.

It's not circular, it's stating the definition of the operator. And
since the definition is so simple, it's impossible - at that level -
for it to be ambiguous. It's possible for equality to be ambiguous, if
you have two types which define __eq__:

class Everyone:
    def __eq__(self, other): return True
class Noone:
    def __eq__(self, other): return False

>>> Everyone()==Noone()
True
>>> Noone()==Everyone()
False

But it's not possible for 'is' to behave like that.

ChrisA



More information about the Python-list mailing list