Python Operators are symbols/words that tell the Python Interpreter to perform or execute certain manipulation tasks. The logical operators are used to combine multiple boolean statements.
There are three logical operators in Python.
Python Logical Operators Flowchart
The below image depicts the flowchart of the logical operators.
Logical AND Operator in Python
The statement returns to be true when both the statements/conditions are true.
a=20 b=10 if a > 0 and b > 0 print("Both a and b are positive numbers.")
Output: Both a and b are positive numbers.
Logical OR Operator in Python
The statement returns to be true when either of the statements/conditions is true.
a=20 b= -10 if a > 0 or b > 0 print("True")
Logical NOT Operator in Python
This operator works with a single value. It reverses the result i.e. if the statement is true, the not operator will turn the statement to false and vice-versa.
a=50 print(not(a % 4 or a > 0))
In the above example, the condition
a % 4 or a > 0 evaluates to True. But, as we have used a not statement, it reverses the result i.e. it provided the result as False.