Logical operators are used to combine statements applying boolean algebra as shown in this article Booleans in Python.
They are:
and
:True
only when both statements are trueor
:False
only when both x and y are falsenot
: Thenot
operator simply inverts the input,True
becomesFalse
and vice versa.
Let’s see a program that shows how each of them is used.
x = 5
y = 2
print(x == 5 and y > 3)
print(x == 5 or y > 3)
print(not (x == 5))
The output is:
False
True
False