A. Python Operator Precedence Table
Operators in Python expression are evaluated in the order shown in Table A.1 for Python 3.0.
Operator |
Description |
---|---|
func(args) |
Function call |
collection[begin : end : step] |
Slicing |
collection[index] |
Indexing |
object.attribute |
Property or member access |
num ** num |
Exponentiation |
~int |
Bitwise NOT |
+num, -num |
Plus/minus sign |
*, /, %, // |
Multiplication, division, remainder division, integer division (when operation is between two numbers); also multiplication of lists and strings: list * n |
+, – |
Addition and subtraction (when operation is between two numbers); also str + str produces string (or list) concatenation |
int << n, int >> n |
Left and right bit ... |
Get Supercharged Python: Take Your Code to the Next Level, First 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.