0<0==0 is false in python Why ??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

0<0==0 is false in python Why ???

Python boolean problem

19th Dec 2019, 11:38 PM
Ayush Kumar
Ayush Kumar - avatar
22 Answers
+ 31
This is called 'chaining'. The expression is translated to: 0<0 and 0==0
19th Dec 2019, 11:45 PM
HonFu
HonFu - avatar
+ 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
20th Dec 2019, 12:54 AM
HonFu
HonFu - avatar
+ 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, <, <=, >, >=, !=, ==
20th Dec 2019, 12:40 AM
HonFu
HonFu - avatar
+ 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.
20th Dec 2019, 7:28 PM
HonFu
HonFu - avatar
+ 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.
20th Dec 2019, 6:30 PM
HonFu
HonFu - avatar
+ 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.
21st Dec 2019, 8:32 AM
David Carroll
David Carroll - avatar
+ 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.
20th Dec 2019, 9:30 PM
HonFu
HonFu - avatar
+ 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.
22nd Dec 2019, 6:35 AM
HonFu
HonFu - avatar
+ 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.
21st Dec 2019, 5:03 PM
HonFu
HonFu - avatar
+ 4
HonFu is there a section in the course (python or other) that describes this situation and the term "chaining"?
20th Dec 2019, 6:02 AM
Petr
+ 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
20th Dec 2019, 1:00 AM
HonFu
HonFu - avatar
+ 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 :)
22nd Dec 2019, 4:00 AM
Selin Genkur
+ 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.
7th Jan 2020, 8:03 PM
David Carroll
David Carroll - avatar
+ 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.
20th Dec 2019, 12:54 AM
rodwynnejones
rodwynnejones - avatar
+ 2
rodwynnejones i understood that but my query is on Mirielle🐶 [Inactive] Answer's about parenthesis
20th Dec 2019, 12:56 AM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Ярослав Вернигора (Yaroslav Vernigora) Как это перевести на наш "called chaining" . Я имею в виду спец термин. Не цепочка же.. .
19th Dec 2019, 11:58 PM
Petr
+ 1
Mirielle🐶 [Inactive] but can you tell me hows it showing False as using parenthesis you can't get False as answer
20th Dec 2019, 12:36 AM
Ayush Kumar
Ayush Kumar - avatar
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.
21st Dec 2019, 12:01 AM
JustAProgramer
JustAProgramer - avatar
0
mein 0<0 and 0==0
21st Dec 2019, 7:26 AM
امير الجبوري
امير الجبوري - avatar