Logical operators are fundamental blocks that can be used to build a decision-making capability in your code. When we need to make our decision based on two or more checks, it is necessary to have a combination of logical operators.
We can do things conditionally in our programs using if statements or if/else statements combined with logical operators. Logical operators work like Boolean variables and return either TRUE or FALSE.
The three most important logical operators are AND, OR and NOT.
AND
Operator The AND operator is used to see if two or more conditions are true. If all the conditions are true, the AND operator returns TRUE. If any one of the conditions fail, the AND operator returns FALSE. In python AND operator is denoted by and keyword. Some other programming languages use “&&” as AND operator.
OR Operator
The OR operator is used to see if either one of two or more conditions is TRUE. If any of the condition is true, the OR operator returns TRUE. If all the conditions fail, the OR operator simply returns FALSE. In python syntax OR operator is denoted by or keyword. Some other programming languages use “||” as OR operator.
NOT Operator
We use the NOT operator to reverse or negate a condition. If the condition is true, NOT will return false and viceversa.
In python programming, not keyword is used to denote not operator. Some other programming languages use “!” as NOT operator.