+ 1

Python challenge questions

I got a challenge question I dont understand 1.) What is the output? x= True y= False print(not x==x or y==y) Answer: True What I dont get is, if x is x and also y is y, that means that both are True. So if i do a print(not true or true), should i get a False as an output?

1st Jan 2020, 7:09 AM
Ben Wong
Ben Wong - avatar
2 odpowiedzi
+ 4
print( not x == x or y == y Is equivalent to: print( ( (not x) == x) or (y == y) ) not and == have the same precedence and are evaluated from left to right; or have grater precedence than not / == 1st: not x 2nd: not x == x 3rd: .... or ...... not x == x is False y == y is True So... False or True is True
1st Jan 2020, 7:25 AM
unChabon
unChabon - avatar
+ 3
((not x==x) = (x != x)) => => ((not True) = (False)) or ((y==y) = True) (False or True) = True
1st Jan 2020, 7:43 AM
Solo
Solo - avatar