A. Python Operator Precedence Table
Operators in Python expression are evaluated in the order shown in Table A.1 for Python 3.0.
Table A.1. Python Operators by Precedence
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 O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.