+ 1

True and False. I'm confused.

a=6 b=7 print(8, not (a==7 and b==6)) print(9, not a==7 and b==6) Why 8, is True? Why 9 ,is False? Both looks the same.

2nd Oct 2023, 7:09 PM
Nick
3 Respostas
+ 8
Nick , the difference of the 2 code samples is how the parenthesis are placed. > in the first sample there is an additional pair of parenthesis used. > in the second sample no additional parenthesis are used. Stefanoo has given the details how the expressions are evaluated.
2nd Oct 2023, 8:03 PM
Lothar
Lothar - avatar
+ 4
It's like math lessons. First parentheses then from left to right. So in the first print statement we have: not (a==7 and b==6) not (false and false) not (false) true And in the second print statement we have: not a==7 and b==6 not false and false true and false false
2nd Oct 2023, 7:52 PM
Stefanoo
Stefanoo - avatar
+ 2
Thank you so much. No more headaches.
2nd Oct 2023, 8:07 PM
Nick