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, ...
Get Python Pocket Reference, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.