+ 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
3 ответов
+ 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