Logical type Of operators

Logical type Of operators

In Python or any other programming language, the logical operators are used for performing logical operations, as their name suggests. These operations are performed on the values of various variables, as required by the coder. The result for all the logical operators is either true or false, based on various conditions. These are the three logical operatorsâ€™ types:

 and Logical AND If both the operands are true, then the condition becomes true, or else the output is False. or Logical OR If any of the two variables do not contain zero, then the condition becomes true. not Logical NOT It is Used to reverse the logical state of the value stored in an operand.

Some important notes:

Here are some key points to remember while dealing with the logical operators in Python:

• In the case of the AND operator, if the first expression is False, then the further expressions are not evaluated.
• In the case of the OR operator, if the first expression is True, then the further expressions are not evaluated.
• Logical NOT operator only uses one single Boolean value to operate. If the provided expression value is True, then the answer is False, and vice versa.
• In the case of using multiple operators in an expression, Python evaluates the results from left to the right.

Example:

#And x = 5 print(not(x > 3 and x < 10)) #or x = 5 print(x > 3 or x < 4) #not x = 5 print(x > 3 and x < 10)

False
True
True