True == 1 weirdness

Steven D'Aprano steve at pearwood.info
Thu Sep 17 03:25:06 CEST 2015


On Thu, 17 Sep 2015 03:47 am, Random832 wrote:

> On Wed, Sep 16, 2015, at 13:33, Steven D'Aprano wrote:
>> On Thu, 17 Sep 2015 01:40 am, Random832 wrote:
>> 
>> > "in" suggests a relationship between objects of different types (X and
>> > "something that can contain X") - all the other comparison operators
>> > are meant to work on objects of the same or similar types.
>> 
>> `is` and the equality operators are intended to work on arbitrary
>> objects,
>> as are their inverses `is not` and inequality.
> 
> But they won't return *true* unless they're the same or similar types.

So what? The intended purpose of `is` and `==` is not to return True. It is
to perform a comparison which may return False, or True.


>> And with operator overloading, < <=  > and => could have any meaning you
>> like:
>> 
>> graph = a => b => c <= d <= e
> 
> Are you suggesting that all objects concerned are a magical "graph node
> object", the <= and [sic] => operators of which return "edge objects",
> the and operator of which constructs a graph object containing all such
> edges? That's *horrifying*. And won't actually work. We haven't actually
> got an => operator, thankfully, and you can't overload 'and'.

Ah yes, well, there is that. Oops.


> I bet you could do it in C++ though.

Almost certainly.




-- 
Steven



More information about the Python-list mailing list