Table of Contents

About

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

Logical Operator

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