Operators
Symbols that combine values: arithmetic, comparison, logical, bitwise, assignment, membership and identity.
Operators follow a precedence order (e.g. * before +, not before and before or). When in doubt, use parentheses.
Sub-topics (7)
Arithmetic Operators
+ - * / // % ** — including true division, floor division, modulo and power.
Comparison Operators
== != < > <= >= compare values and return True or False; they can be chained.
Logical Operators
and, or, not — with short-circuit evaluation that returns one of the operands.
Bitwise Operators in Python
& | ^ ~ << >> work on the binary representation of integers.
Assignment Operators
= plus augmented forms like += -= *= /= //= %= **= &= |= and the walrus :=.
Membership Operators
in and not in test whether a value is contained in a sequence, set or dict.
Identity Operators
is and is not check whether two names refer to the very same object.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.