Saturday, February 9, 2019

Logical Operators

Logical Operators:

+------------+-----------------+
|     or     |   Logical OR    |
|     and    |   Logical AND   |
|     not    |   Logical NOT   |
+------------+-----------------+

Logical operators are often used to join two conditional expressions or with Boolean variables or constants. Below are some examples to illustrate each operator.

Logical or:
Logical or operator evaluates to True if any of the operands is True. It results in False only if both the operands are False.

+--------------------+---------------+
|      Examples      |    Results    |
+--------------------+---------------+
|    True or True    |     True      |
|   False or False   |     False     |
|    True or False   |     True      |
|   3 < 4 or 5 > 7   |     True      |
|  3 == 4 or 5 >= 7  |     False     |
|  4 == 4 or 7 >= 4  |     True      |
+--------------------+---------------+

Logical and:
Logical and operator evaluates to False if any of the operands is False. It results in True only if both the operands are True

+---------------------+---------------+
|      Examples       |    Results    |
+---------------------+---------------+
|    True and True    |     True      |
|   False and False   |     False     |
|    True and False   |     False     |
|   3 < 4 and 5 > 7   |     False     |
|  3 == 4 and 5 >= 7  |     False     |
|  4 == 4 and 7 >= 4  |     True      |
+---------------------+---------------+

Logical not:
Logical not operator is used to find the complement of a Boolean variable, constant or expression. In other words, the not operator turns True to False and False to True.

+---------------------+---------------+
|      Examples       |    Results    |
+---------------------+---------------+
|      not True       |     False     |
|      not False      |     True      |
|      not 3 < 4      |     False     |
|      not 3 == 4     |     True      |
|      not 7 >= 4     |     False     |
+---------------------+---------------+

.

No comments: