DeMorgan's Law
DeMorgan's law is a simple law that I learned at UPT during one of my hardware classes. While it is useful in hardware it, it is also useful when writing programs.
If you have a condition like not (A and B)
, you can rewrite it to !A or !B
.
if __name__ == '__main__':
a = True
b = True
if not (a and b):
print("True")
else:
print("False")
if not a or not b:
print("True")
else:
print("False")