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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.