Wednesday, June 3, 2020

Logical Operators


and operator


It’s a binary operator with a priority that is lower than the one expressed by the comparison operators. It allows us to code complex conditions without the use of parentheses like this one.


Counter > 0 and value == 100


The truth table is given below.


or operator


This is a disjunction operator. It’s a binary operator with a lower priority than “and”.

The truth table is given below.




not operator


This is a unary operator performing a logical negation. It turns truth into falsehood and falsehood into truth.



Logical Expressions


See the below code lines & outputs.











In Python,

not (p and q) == (not p) or (not q)
not (p or q) == (not p) and (not q)

No comments:

Post a Comment