+ 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

21st Jul 2020, 11:51 AM
Subrath
Subrath - avatar
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
21st Jul 2020, 11:56 AM
Saphal Poudyal
Saphal Poudyal - avatar
+ 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
21st Jul 2020, 11:55 AM
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜
˜”*°•.˜”*°• Mohan 333 •°*”˜.•°*”˜ - avatar
+ 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
21st Jul 2020, 11:58 AM
Rawley
Rawley - avatar
+ 3
Thanks a lot Mohan 333 and Ćheyat
21st Jul 2020, 11:58 AM
Subrath
Subrath - avatar
+ 2
Ćheyat Your explanation is very good. I like it. Thanks.
21st Jul 2020, 5:38 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar