Home / python Tutorial / Reference / Python Operators
Python Operators
Last updated: 2026-09-22
Python Operators
A category-grouped reference of Python operators: arithmetic, assignment, comparison, membership & identity, logical, and bitwise. Each entry comes with a syntax glance and a runnable example.
Python supports the following groups: Arithmetic Operators Comparison Operators Assignment Operators Logical Operators Bitwise Operators Membership Operators Identity Operators Operator Precedence
Arithmetic Operators
Operator Meaning Example +Addition / concatenation — + sums numbers and concatenates sequences. a + b-Subtraction / set difference — - subtracts numbers and computes set difference. a - b*Multiplication / repetition — * multiplies numbers and repeats sequences. a * b/True division — / always returns float; use // for integer division. a / b//Floor division — // returns the floor of division. a // b%Modulo — % returns the remainder of division. a % b**Power — ** computes a raised to the power b. a ** b@Matrix multiply — @ is the matrix-multiplication operator (PEP 465); used by NumPy etc. a @ b
Comparison Operators
Operator Meaning Example ==Equal — == tests equality (delegated to __eq__). a == b!=Not equal — != is the negation of ==. a != b<Less than — < tests a < b (via __lt__). a < b>Greater than — > tests a > b (via __gt__). a > b<=Less or equal — <= tests a <= b (via __le__). a <= b>=Greater or equal — >= tests a >= b (via __ge__). a >= b
Assignment Operators
Operator Meaning Example =Simple assignment — = binds the value of the right-hand expression to the name on the left. name = expression+=Addition assignment — += adds the right value to the left variable, equivalent to x = x + y; for a list it appen... x += y-=Subtraction assignment — -= subtracts the right value from the left variable, equivalent to x = x - y. x -= y*=Multiplication assignment — *= multiplies the left variable by the right value, equivalent to x = x * y; for str/list ... x *= y/=Division assignment — /= divides the left variable by the right value, returning a float, equivalent to x = x / ... x /= y//=Floor division assignment — //= floor-divides the left variable by the right value (rounding down), equivalent to x = ... x //= y%=Modulo assignment — %= takes the modulo of the left variable by the right value, equivalent to x = x % y. x %= y**=Power assignment — **= raises the left variable to the power of the right value, equivalent to x = x ** y. x **= y@=Matrix multiplication assignment — @= performs an in-place matrix multiplication of the left variable by the right, equivalen... x @= y&=Bitwise AND assignment — &= computes a bitwise AND of the left variable with the right value, equivalent to x = x &... x &= y|=Bitwise OR assignment — |= computes a bitwise OR of the left variable with the right value, equivalent to x = x | ... x |= y^=Bitwise XOR assignment — ^= computes a bitwise XOR of the left variable with the right value, equivalent to x = x ^... x ^= y<<=Left shift assignment — <<= shifts the bits of the left variable left by the amount of the right value, equivalent... x <<= y>>=Right shift assignment — >>= shifts the bits of the left variable right by the amount of the right value, equivalen... x >>= y:=Walrus operator — := (PEP 572) assigns a value as part of an expression and returns it. name := value
Logical Operators
Operator Meaning Example andBoolean AND (short-circuit) — and is short-circuit boolean AND; returns first falsy or last truthy. a and borBoolean OR (short-circuit) — or is short-circuit boolean OR; returns first truthy or last falsy. a or bnotBoolean NOT — not returns the boolean negation (True / False). not a
Bitwise Operators
Operator Meaning Example &Bitwise AND / set intersection — & is bitwise AND; on sets it's intersection. a & b|Bitwise OR / set union — | is bitwise OR; on sets it's union. a | b^Bitwise XOR / set symmetric difference — ^ is bitwise XOR; on sets it's symmetric difference. a ^ b~Bitwise NOT — ~ inverts all bits: ~x == -(x+1). ~a<<Left shift — << shifts bits left by n; equivalent to a * (2**n). a << n>>Right shift — >> shifts bits right by n; equivalent to floor(a / (2**n)). a >> n
Membership Operators
Operator Meaning Example inMembership test — in checks containment; also drives for-loops. x in containernot inNegated membership — not in is the negation of in. x not in container
Identity Operators
Operator Meaning Example isIdentity test — is tests identity (same object in memory). a is bis notNegated identity — is not is the negation of is. a is not b
Operator Precedence
Operator Description
(...), [...], {k: v}, {...}Parentheses / list / dict / set
x[i], x[i:j], x(args), x.attrSubscription, slice, call, attribute
await xawait expression
**Exponentiation
+x, -x, ~xUnary plus, minus, bitwise NOT
*, @, /, //, %Multiply, matmul, divide, floor-divide, modulo
+, -Addition, subtraction
<<, >>Shift left, shift right
&Bitwise AND
^Bitwise XOR
|Bitwise OR
in, not in, is, is not, <, <=, >, >=, !=, ==Comparisons, membership, identity
not xLogical NOT
andLogical AND
orLogical OR
if ... elseConditional expression
lambdalambda expression
:=Assignment expression (walrus)
Web-Tutorial Tech Team
A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.
About Us