An expression is any piece of code that produces a value. Operators are the symbols that combine values into expressions: +, -, ==, and, and many more.
This section walks through every kind of operator Python offers.
What’s in this section
- Arithmetic operators — add, subtract, multiply, divide, modulo, exponent
- Comparison operators — equal, less than, greater than
- Logical operators —
and,or,not, and short-circuit behaviour - Assignment operators —
=,+=,-=, and friends - Membership and identity —
in,not in,is,is not - The ternary operator — a one-line
if/else
Most of these will feel familiar from maths class. The ones that won’t — is vs ==, short-circuiting, the ternary — are the ones to slow down on.