I have some code here:
m = None
n = None
if not m:
print "Something happens"
>>> Something happens
if I do:
if not m and n:
print "Something happens"
Nothing happens.
But I can do:
m, n = 1,2
if m and n:
print "Something happens"
>>> Something happens
Why are if and if not handled the same way? Does ‘if not’, not take ‘and’ statements?
Thank you
You have an operator precedence problem.
if not m and nis equivalent toif (not m) and n. What you want isif not m and not norif not (m or n).See also: De Morgan’s Laws