22 ответов
+ 31
This is called 'chaining'.
The expression is translated to:
0<0 and 0==0
+ 14
Python does it differently than for example C.
In C you always have to write stuff like...
lowerEdge<middle&&middle<upperEdge
... if you wanted to check that the middle is actually in the middle.
Python has the shortcut:
lower < middle < upper
And this is read like lower<middle AND middle<upper in C.
0<0==0 would go like this:
0<0 and 0==0
False and True
False
+ 13
Mirielle🐶 [Inactive], the operators that can be chained in this way are all of the same precedence and will be evaluated from left to right.
It's these ones:
in, not in, is, is not, <, <=, >, >=, !=, ==
+ 9
That's right, Mirielle🐶 [Inactive], god forbid anyone ever told *you* what to do!
Don't even try to once listen and reflect your own behavior.
I seriously pity swim, who's always investing a lot of energy to help people here.
If someone told me 'you're wrong, I know everything better, you don't understand this, but I have only read 1% of what you wrote', I'd just fall silent.
+ 8
Mirielle🐶 [Inactive], seriously, if you have no time engaging in a proper discussion, why are you discussing in the first place?
You're just wasting everybody's time, including your own, if you just pick any line from what the other person said, and hip-shoot at it.
Just wait until you have the time. Then read. Then think. And only then answer.
+ 7
Petr, I've found some article:
https://www.geeksforgeeks.org/chaining-comparison-operators-JUMP_LINK__&&__python__&&__JUMP_LINK/
+ 7
Ayush Kumar If I may, I'd like to expand on the selected answer posted by HonFu and address some of the other questions that followed.
First, chained comparisons are one of the few features I actually like about Python.
Consider the following:
0 < 0 == 0
Produces disassembled bytecode equivalent to:
0 < 0 and 0 == 0
The second comparison will not be evaluated because it will be short circuited by the first comparison, which evaluates to false.
Now, consider:
(0 < 0) == 0
or
0 < (0 == 0)
Neither of these are chained comparisons because the parentheses make these equivalent to:
(group) == 0
or
0 < (group)
As reflected in the disassembled bytecode.
It should also be noted that chained comparisons apply to comparison operators rather than arithmetic operators.
Therefore, arithmetic order of operations and groups would not apply to chained comparisons.
You can review and compare the disassembled bytecode:
https://code.sololearn.com/coEUvJh40ufQ/
I hope this was helpful.
+ 6
Mirielle🐶 [Inactive], this is becoming more and more silly really.
No one forces you to read anything - just as no one forces you to even answer.
Which you shouldn't, if you have no time, energy, and also no interest really.
IF you answer, you should read and think first.
In a discussion, you're supposed to listen to the argumentation of the other person and react to it, not just randomly pick any line. This makes any debate utterly futile and leads to no result.
Try it in your college course, tell the professor:
'Nah, I didn't agree with your first sentence, so I just zoned out and stopped to listen. But what you said is wrong anyway.'
I will now stop discussing about this, because you are clearly unwilling or unable to accept valid criticism and reconsider your behavior.
+ 6
Selin Genkur, did I 'win'? I can't even remember!
Because thanks to the lady lalala-finger-in-my-ears I can't read any of it anymore. :-P
I believe she should work at the vulnerability. That attitude won't fly anymore as soon as she leaves college.
+ 5
If there is any reason for that intense love, I wouldn't ever know since I can't read anything written by she who can't be criticized.
+ 3
Mirielle🐶 [Inactive]'s variations would play out like this:
(0<0)==0
(False)==0
0==0
True (because False, as a number is 0)
0<(0==0)
0<(True)
0<1
True, because True as a number counts as 1
+ 3
I always admired her brilliance and confidence. Now I see she doesn't like to admit when she's wrong, and I think that's a vulnerability. I thought she needed some love in this situation :D
Btw, I love you too, HonFu :) But you won, so you didn't needed it in this situation :)
+ 3
Mirielle🐶 I'm attempting to review this entire thread and I believe I may have locked in on where there might be some confusion with multiple contexts and multiple points being made.
Please... everyone... refrain from responding as I'd like to attempt to shed some light on what may be the points of disagreement, and possibly the source of confusion.
+ 2
@Ayush Kumar
I think you've miss-understood HonFu's answer. The "and" in.. "0<0 and 0==0" is a logical "and"...so
0 < 0....=> False.
0==0....=> True
So...
False "and" True ...=> False.
+ 2
rodwynnejones i understood that but my query is on Mirielle🐶 [Inactive] Answer's about parenthesis
+ 1
Ярослав Вернигора (Yaroslav Vernigora)
Как это перевести на наш "called chaining" . Я имею в виду спец термин. Не цепочка же.. .
+ 1
Mirielle🐶 [Inactive] but can you tell me hows it showing False as using parenthesis you can't get False as answer
0
I think 0<0==0 is false because, if you think about it it’s like this:
0<0 is basically 1<1 these numbers are equal they can’t be less or more.
zero is less than zero is equal to zero.
You can disagree or correct me.
0
mein
0<0 and 0==0