+ 1

I REALLY Don't Understand The Operator Precedence Lesson, Especially The 3rd Example

I somewhat understand >>> False == False or True True ...because we need just one of them to be False for it to be true, and >>> False == (False or True) False happens because (False or True) in a bracket returns True by default. At least that's what I understand from the comments on the question. Someone PLEASE let me know if I have this understanding correct, or if there's something I'm missing. HOWEVER... >>> (False == False) or True True just doesn't make sense to me. I think it's the bracket that's messing me up. Let me make sure I understand this: the bracket resolves to False, which ends up being False or True, which resolves to True? Is it because there's no equal sign anywhere, which means it returns True by default? I'm just so confused. Sorry for the long wall of text. I'm new to this and I really don't have anyone to speak to, and I haven't seen anyone in the comments phrase it the way I'm doing it.

7th Mar 2020, 12:41 PM
Jevvy
3 Antworten
+ 3
No, your first "understanding" is wrong. False == False or True is (False == False) or True Because False == False is True True or True returns True. You don't need equal sign to compare values for Boolean. Because Boolean itself is Boolean https://code.sololearn.com/cdTHf0j9bj42/?ref=app See this demo, last one is True, because it is not (False) == (True or True), instead it is something or True.
7th Mar 2020, 12:53 PM
Gordon
Gordon - avatar
0
@Gordon honestly didn't really understand what you meant. I think this is so basic (and probably something you learned so long ago) that it's probably difficult to understand it from such a lowly level such as mine haha. What I'm thinking you're doing is that, for False == False or True, you are simply putting the brackets around the part that you're solving first, which is False == False, which is True (kinda contradictory in my head but I need to learn to think like a programmer). Then it becomes True or True, which is obviously True. I watched numerous Youtube videos to see the different ways people explained this whole concept, then came back to you to see if I learned anything or not. I will be going through your Demo to make sure I understand each one. Thank you very much for your help.
7th Mar 2020, 3:36 PM
Jevvy
0
Sorry I should phrase better. Your current problem is that, because you see assignments, such as var1 = 3 + 4 So, you misunderstood that Boolean must be comparison print( 3 == 3 ) # True print( 100 > 99 ) # True if we have both logic operator and comparison, it is like print( 3 > 4 and 100 > 9 ) #False Now if we don't have comparison, we only have Boolean, it is also Ok, print( False or True ) #True Now, if we have both equality and boolean, print( False == False or True ) == should have higher precendence, which means it gets evaluated first, so False == False becomes True then, it becomes True or True so the result is True. "Predence" means which one is evaluated earlier, which one is evaluated later. You can find a table in the second page of the concerned lesson. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2280/ > < >= <= == not these are evaluated earlier than and or
7th Mar 2020, 3:58 PM
Gordon
Gordon - avatar