Built-in Types and Operators
Operators and Precedence
Table 1-1 lists Python’s expression operators. Operators in the lower cells of this table have higher precedence (i.e., bind tighter) when used in mixed-operator expressions without parentheses.
Table 1-1. Python 3.0 expression operators and precedence
Operator | Description |
|---|---|
| Generator function
|
| Anonymous function maker |
| Ternary selection
( |
| Logical |
| Logical |
| Logical negation |
| Membership: iterables, sets |
| Object identity tests |
| Magnitude comparisons, set subset and superset |
X == Y, X != Y | Equality operators |
| Bitwise |
| Bitwise exclusive
|
| Bitwise |
| Shift |
| Addition/concatenation, subtraction/set difference |
| Multiplication/repetition, remainder/format, division, floor division |
| Unary negation, identity |
| Bitwise NOT complement (inversion) |
| Power (exponentiation) |
| Indexing (sequence, mapping, others) |
| Slicing (all bounds optional) |
| Call (function, method, class, other callable) |
| Attribute reference |
| Tuple, expression, generator expression |
| List, list comprehension |
| Dictionary, set, dictionary and set comprehension |
Operator Usage Notes
In Python 2.6, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access