Cheat Sheet
Operators Priority
Python Operators and Expressions
Python Expressions Documentation
| Category | Operators | Description |
|---|---|---|
| Parentheses | () | Grouping expressions |
| Exponentiation | ** | Power operation |
| Unary Operators | +x, -x, ~x | Positive, negative, bitwise NOT |
| Arithmetic | *, /, //, %, +, - | Multiplication, division, floor division, modulo, addition, subtraction |
| Bitwise Shift | >>, << | Right shift, left shift |
| Bitwise Operations | &, ^, | | AND, XOR, OR |
| Comparisons | >, >=, <, <=, ==, != | Greater than, greater or equal, less than, less or equal, equal to, not equal |
| Logical Operations | and, or, not | Logical AND, OR, NOT |
| Assignment | =, +=, -=, *=, /=, %=, **=, //= | Simple and augmented assignments |
| Identity | is, is not | Object identity comparison |
| Membership | in, not in | Collection membership test |
Notes
- Python doesn't have increment
++or decrement--operators - Python uses
and,or,notinstead of&&,||,! - The
//operator performs floor division - The
isoperator checks if two objects share the same memory location - Chained comparisons like
a < b < care allowed