+ 1

output of python....Are (not 4 in nums) and (4 not in nums) same.....??

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 >>>

6th Apr 2018, 9:40 AM
Smriti Rastogi
Smriti Rastogi - avatar
1 Answer
+ 5
Let's see each statements 1. print(not 4 in nums) # not(4 in nums) # 4 in nums ? -> False as 4 is not contained in list # not(False) -> True # True 2. print(4 not in nums) # 4 is not in nums. So that's True 3. print(not 3 in nums) # not( 3 in nums) # not(True) # False 4. print(3 not in nums) #Since 3 is in nums . #False So basically (not 4 in nums ) means first check if( 4 is in nums) then find the negation(not) of the result obtained. -> 4 in nums i.e False and Not of False evaluates to True. whereas 4 not in nums means return True if 4 is not in nums , else return False -> 4 not in nums evaluates to True since 4 is not contained in nums.
6th Apr 2018, 10:00 AM
Bishal Sarang
Bishal Sarang - avatar