+ 2
logic behind this:
x = 4 y = 2 if not 1 + 1 == y or x == 4 and 7 == 8: print("Yes") elif x > y: print("No") Can anyone please clear me above code line to line?
4 Antworten
+ 4
Order of precedence: == > Not > And > Or
Step 1-
Evaluate all "==" first.
(not 1+1==y or x==4 and 7==8 )
=> (not True or True and False )
Step 2-
Evaluate "not"
=> (False or True and False )
Step 3-
Evaluate "and"
=> (False or False )
Step 4-
Evaluate "or"
=> (False )
So now the code is simplified to
if False==True:
print("Yes")
elif x>y:
print("No")
Hope it helped. 🤗
+ 2
DeWill Firstly, 7==8 gives False i.e. 0 *instead of* 1. You can check it out in Code Playground.
Secondly, comparison operator like '==' have higher precedence than 'not' operator. So,I think that 1+1==y gets evaluated first, then 'not' operator is used on it.
Mods, please correct me if I am wrong.
+ 2
My bad.... 😅
Thanks for correcting me.....
+ 1
DeWill Its ok. I am also learning..we all are here to learn 😁