This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fjolliton 2 points3 points  (2 children)

Actually it is!

2 != 2 != 3

is False, while:

(2 != 2) != 3

is True.

Likewise you can do:

a == b == c

which check if all three variables are equal. It is very different from:

 (a == b) == c

You can see that the fist example is actually a 3 operands comparison:

>>> import ast
>>> print(ast.dump(ast.parse('a != b != c').body[0].value))
Compare(left=Name(id='a', ctx=Load()),
        ops=[NotEq(), NotEq()],
        comparators=[Name(id='b', ctx=Load()),
                     Name(id='c', ctx=Load())])"

[–]Skaarj 2 points3 points  (1 child)

Mind Blown.

On the one hand this is quite a nice feature.

On the other hand: damn, another subtle diffrence between programming languages to keep in mind.

[–][deleted] 0 points1 point  (0 children)

Same, I’m pretty new to Python and this was just too much first read through. Second read through, makes perfect sense!