Logical Operators
What are Logical operators
Logical operators are operators that combines at least two expressions which returns either True or False when evaluated.
Logical Operators in Python
There are three logical operators in Python
and
Logical operator
and
Logical operator will return True
if all the expressions evaluate to True
x | y | x and y |
---|---|---|
False | False | False |
False | True | False |
True | False | False |
True | True | True |
Example
or
Logical operator
or
Logical operator will return True
if at least one of the expression evaluates to True
, else it will return False
x | y | x or y |
---|---|---|
False | False | False |
False | True | True |
True | False | True |
True | True | True |
Example
not
Logical operator
not
Logical operator returns the oppsite boolean value of its operand. If the operand value is True the it will return False, else it will return True
x | not x |
---|---|
False | True |
True | False |