+ 2
Can anyone explain me this ....pls
nums = [1, 2, 3] print(not 4 in nums) print(4 not in nums) print(not 3 in nums) print(3 not in nums) Output - True True False False
5 Answers
+ 4
'not' operator does the opposite of any boolean type variable.
not 4 in nums:
checks if '4' is in nums. In this case it isn't. So the condition returns false. The 'not' keyword then flips the value . As a result , you get true.
4 not in nums :
checks if the value '4' is not in nums. In this case 4 is not in nums and thus you get true printed and vice versa
+ 4
Outputs:
1.4 is not in the list so True.
2. Same to 1st output.
3. 3 in the list. So it print False.
4. Same to 3rd output
+ 3
Well it seems,
â˘prints true because there is not 4 in the array(nums)
â˘the same condition
â˘prints false because there is 3 in the array(nums), so the condition fails.
â˘similary
+ 2
Äheyat Your explanation is very good. I like it. Thanks.