Logical operators are used to combine statements applying boolean algebra as shown in this article Booleans in Python.
They are:
and:Trueonly when both statements are trueor:Falseonly when both x and y are falsenot: Thenotoperator simply inverts the input,TruebecomesFalseand 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