Why this evaluation is false? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Why this evaluation is false?

nums = [1, 2, 3] print(not 5 and not 4 in nums) It gives me false, althoug true and true operation is in print.

11th Jan 2019, 7:31 PM
Cris S
Cris S - avatar
6 Answers
+ 4
The order of evaluation for these operators: 1. in 2. not 3. and so the print can be expressed like this: print((not 5) and (not (4 in nums))) (not 5) is False because the boolean value of any nonzero integer is True bool(5) = True therefore (not 5) = (not True) = False While the second part of the expression evaluates to True, it doesn't matter because (False and True) = False
12th Jan 2019, 10:30 AM
Tibor Santa
Tibor Santa - avatar
+ 5
not 5 => false
11th Jan 2019, 8:08 PM
Ulisses Cruz
Ulisses Cruz - avatar
+ 5
Correct line is: print(not 5 in nums and not 4 in nums) -> True
11th Jan 2019, 10:13 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 1
What's that ?
17th Jun 2019, 8:21 PM
Nurbolot Gulamidinov
Nurbolot Gulamidinov - avatar
+ 1
Why are you
17th Jun 2019, 8:21 PM
Nurbolot Gulamidinov
Nurbolot Gulamidinov - avatar
+ 1
I'm angry because I'm do not understand
17th Jun 2019, 8:21 PM
Nurbolot Gulamidinov
Nurbolot Gulamidinov - avatar