Python - Boolean Operator (And|Or|Not)

Card Puncher Data Processing


Boolean - (Logical) Operator (OR, AND, XOR, ) in Python

Logical Operator


Boolean operators (or logical operators) are words used to connect statements. They result in boolean values—True or False.

  • and,
True and True is True
True and False is False
False and True is False
False and False is False

  • or. It returns True when either (meaning one, the other or both) of the expressions on each side of or are true. It's only False when both expressions are False.
True or True is True
True or False is True
False or True is True
False or False is False

  • not
Not True is False
Not False is True

Order of precedence

There is an order of precedence for boolean operators. The order is as follows:

  • not is evaluated first;
  • and is evaluated next;
  • or is evaluated last.

This order can be changed by including parentheses (()).

Documentation / Reference

Discover More
Card Puncher Data Processing
Python - Control flow (Comparator, Boolean Operator and Conditional Statement)

in Python Equal to (==) Not equal to (!=) Less than (<) Less than or equal to (<=) Greater than (>) Greater than or equal to (>=) In (for a string or a list) Comparisons generate...

Share this page:
Follow us:
Task Runner