Python Bool Operators

by Atakan

We can split Boolean Operators to 3.

  • and
  • or
  • not

However, membership operators are divided into 2

  • in
  • not in

Let’s look at the examples

print(True and True)  # True
print(True and False)  # False
print(False and False)  # False
print(1 > 0 and 0 < 1)  # True
print(3 == 2 or 3 == 3)  # True
print(True or False)  # True
print(False or True)  # True
print(False or False)  # False
print(not False)  # True
print(not True)  # False
print(not (5 > 1))  # False
print(not (1 > 5))  # True

# Membership operators
print(1 in [2, 3, 4, 6, 7])  # False
print(2 in [2, 3, 4, 6, 7])  # True

print(1 not in [2, 3, 4, 6, 7])  # True
print(2 not in [2, 3, 4, 6, 7])  # False

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. OK Read More