Python Complete Reference Index
Select any item below to open its full syntax specification, parameters, and live example.
Language Delimiters
! — exclamation!
Introduces an explicit conversion inside an f-string replacement field, such as !r, !s or !a. It is also part of the separate != operator; Python has no standalone prefix ! negation.
( — left parenthesis(
Opens a parenthesized expression, argument list or parameter list. Parentheses permit implicit line joining; a single parenthesized expression is not a tuple unless it contains a comma.
) — right parenthesis)
Closes the matching opening parenthesis. It ends the enclosed expression or argument list, after which outer operations can continue.
, — comma,
Separates items, arguments or parameters. In expression lists a comma constructs a tuple even without parentheses, and a trailing comma is needed for a one-item tuple.
-> — return annotation arrow->
Introduces a function return annotation between the parameter list and the colon. It describes an intended result type but does not by itself enforce that type at runtime.
Operators
!= — Value inequalityleft != right
Tests inequality. The default __ne__ delegates to __eq__ and negates the result unless it is NotImplemented, but a custom class can define its own inequality independently. When both implementations decline, inequality falls back to nonidentity. NaN compares unequal even to itself. Rich comparisons share precedence and support chaining: the middle operand is evaluated once, and later operands are skipped when a preceding comparison is falsy. Custom __ne__ results need not be bool. Custom dispatch uses __ne__ and the counterpart __ne__ on the other operand; a right-hand subclass may have priority.
% — Remainder and percent formattingleft % right
For built-in real numbers computes the remainder associated with floor division. For integers a nonzero remainder has the divisor’s sign; float rounding can affect the usual magnitude relationship. Zero divisors raise ZeroDivisionError, and complex values are not supported. With str or bytes on the left, % also supports legacy formatting rather than numeric division. Custom behavior is provided by __mod__ and __rmod__.
%= — Remainder assignmenttarget %= expression
Update a number with its remainder, or a string or bytes object with percent-style formatting. For integer operands a nonzero remainder has the divisor’s sign. Formatting immutable strings replaces the binding rather than changing the original string. The __imod__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
& — Bitwise AND and set intersectionleft & right
For integers, keeps bit positions where both operands have a one. For two bool operands returns a bool; mixing bool and int yields an int for built-in operands. Set operands compute intersection. This operator evaluates both operands and is not the short-circuit and keyword. __and__ and __rand__ implement custom behavior. Shifts bind more tightly than &, which in turn binds more tightly than ^ and |.
&= — Bitwise AND assignmenttarget &= expression
Update an integer with the bitwise intersection of its bits, or a mutable set with the intersection of its elements. This operation evaluates the right operand and is not short-circuiting Boolean and. The __iand__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
* — Multiplication and sequence repetitionleft * right
Multiplies numeric operands; with a supported sequence and an integer-like repetition count, it repeats the sequence. Negative counts produce empty sequences. Repetition does not clone referenced elements, so repeated nested mutable values can alias. Custom classes can implement __mul__ or __rmul__. This operator shares precedence with division and matrix multiplication, and binds more tightly than addition.
** — Exponentiationleft ** right
Raises the base to the exponent. Nonnegative integer exponents on integer bases yield integers, whereas negative integer exponents yield floats. A negative real base with a nonintegral exponent may produce a complex result. Zero raised to a negative power raises ZeroDivisionError. ** groups from right to left; -2**2 means -(2**2), but 2**-2 is valid. __pow__ and __rpow__ provide custom behavior. For modular exponentiation use three-argument pow().
**= — Exponentiation assignmenttarget **= expression
Store a power of the existing value. A negative integer exponent can turn an integer into a float. Built-in zero raised to a negative exponent raises ZeroDivisionError. For x **= 3 ** 2, the exponent is evaluated as 3 ** 2 before the outer operation. The __ipow__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
*= — Multiplication assignmenttarget *= expression
Scale a number or repeat a supported sequence. List repetition updates the same outer list and duplicates references, not nested objects. For mutable sequences, a nonpositive integer repetition count clears the sequence. The __imul__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
+ — Addition and concatenationleft + right
Adds compatible numbers or joins compatible sequences. Built-in mixed numeric arithmetic promotes to a suitable common numeric type; list concatenation creates a new outer list without copying nested items. __add__ and __radd__ implement custom behavior; a more specific right-hand subclass can receive priority. Returning NotImplemented lets dispatch consider another implementation. Unlike +=, ordinary + does not request in-place addition. Multiplication binds more tightly than addition. For operands of the same type, a declined forward operation does not trigger the reflected method; unsupported arithmetic normally raises TypeError.
+ — Unary positive+operand
Applies the unary positive operation. For ordinary int, float and complex values it preserves the numeric value, though +True produces an int. It is not a general conversion or copying operation. Custom __pos__ implementations can return a different object; Decimal unary plus, for example, is affected by its arithmetic context. Unary operators bind more tightly than multiplication but less tightly than a power on their right.
+= — Addition assignmenttarget += expression
Increase numeric values or extend supported sequences. A list extends in place and accepts an iterable, whereas integer addition rebinds the target. An immutable tuple can contain a list that is extended before tuple item reassignment raises TypeError. The __iadd__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
- — Subtraction and set differenceleft - right
For built-in numbers subtracts the right operand from the left. For sets and frozensets it selects elements present in the left but absent from the right; the result has the left set type for mixed built-in set operands. Ordinary sequences do not support subtraction. __sub__ and __rsub__ provide custom dispatch, including reflected fallback. Binary subtraction associates left to right and differs from unary negation.
- — Unary negation-operand
Negates built-in numeric values, including complex numbers. It invokes __neg__ on custom types, which may return nonnumeric results. Unary minus is not the same operator as binary subtraction. In -2**2, exponentiation occurs before negation; parentheses change the base. Negative zero can be meaningful for floats even though it compares equal to positive zero.
-= — Subtraction assignmenttarget -= expression
Reduce a numeric value or remove elements from a mutable set by difference. A set updates in place, while a frozenset is replaced by a new result as needed. Ordinary lists do not implement subtraction. The __isub__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.
Showing 20 of 1507 entries