+ 1
what's the difference between "not 4 in" and "4 not in"
nums = [1, 2, 3] print(not 4 in nums) print(4 not in nums) print(not 3 in nums) print(3 not in nums)
2 ответов
+ 3
There is basically no difference between the 2. At least as far as the outcome of the operation is concerned.
"not 4 in nums" is the same as taking the result from "4 in nums" and negating it. Or
not(4 in nums) the "4 in nums" returns false and is then negated by "not", making it true.
Where "4 not in nums" the "not in" is the negation "in" operator and returns true if 4 is not present in the list nums.
0
我