Next / Previous / Contents / TCC Help System / NM Tech homepage

19. Operators and expressions

Python's operators are shown here from highest precedence to lowest, with a ruled line separating groups of operators with equal precedence:

Table 6. Python operator precedence

(E) Parenthesized expression or tuple.
[E, ...] List.
{key:value, ...} Dictionary or set.
`...` Convert to string representation.
x.attribute Attribute reference.
x[...] Subscript or slice; see Section 8.1, “Operations common to all the sequence types”.
f(...) Call function f.
x**y x to the y power.
-x Negation.
~x Bitwise not (one's complement).
x*y Multiplication.
x/y, x//y Division. The “//” form discards the fraction from the result. For example, “13.9//5.0” returns the value 2.0.
x%y Modulo (remainder of x/y).
x+y Addition, concatenation.
x-y Subtraction.
x<<y x shifted left ybits.
x>>y x shifted right ybits.
x&y Bitwise and.
x^y Bitwise exclusive or.
x|y Bitwise or.
x<y, x<=y, x>y, x>=y, x!=y, x==y Comparisons. These operators are all predicates; see Section 19.1, “What is a predicate?”.
x in y, x not in y Test for membership.
x is y, x is not y Test for identity.
not x Boolean “not.”
x and y Boolean “and.”
x or y Boolean “or.”