Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any advantage to using De Morgan's laws in python?

Tags:

People also ask

Is Demorgans law useful?

De Morgan's Law Formula Demorgan's Law is used both in set theory as well as in boolean algebra. These laws are critical in understanding mathematical arguments. Using these laws a relationship can be established between union and intersection via complementation.

How do De Morgan's laws help to improve your code?

Summary. De Morgan's Laws can help simplify your code to make it more readable. You can change a sequence of negated ands to something that reads as “at least one of these is required” and a sequence of negated ors to something that reads as “all of these are required.”

What are the implications of de Morgan's theorems?

The Demorgan's theorem defines the uniformity between the gate with the same inverted input and output. It is used for implementing the basic gate operation likes NAND gate and NOR gate. The Demorgan's theorem mostly used in digital programming and for making digital circuit diagrams.


I use pycharm and a few times when using if statements I have seen the suggestion to change the statement using De Morgan laws, such as with the following if statement:

if new_odds > 10 and new_odds <= 30:

if not (not (new_odds > 10) or not (new_odds <= 20)):

For me it makes it less readable, so is there any advantage to using De Morgan's laws or is it strictly a personal choice?