I was testing some code where i wanted to print if x is in dictionary or not.
my code was
temp_dict = {...}
if x not in temp_dict:
# Do something
pass
However this didn't work, even though x wasn't present in temp_dict
the if
wasn't evaluated to True and its body wasn't executed (of course).
When I changed it to
temp_dict = {...}
if not x in temp_dict:
# Do something
pass
it worked!
Can somebody please explain the difference?