Explanatory Question
What is the precedence of operators in Python?
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.
| Precedence | Operator | Description |
|---|---|---|
| 1 | () | Parentheses (grouping) |
| 2 | +x, -x | Positive, negative |
| 3 | ** | Exponentiation |
| 4 | *, /, //, % | Multiplication, division, floor division, modulus |
| 5 | +, - | Addition, subtraction |
| 6 | <<, >> | Bitwise shift operators |
| 7 | & | Bitwise AND |
| 8 | ^ | Bitwise XOR |
| 9 | | | Bitwise OR |
| 10 | <, <=, >, >= | Comparison operators |
| 11 | ==, != | Equality operators |
| 12 | not | Logical NOT |
| 13 | and | Logical AND |
| 14 | or | Logical OR |
| 15 | if else | Conditional expression |
| 16 | =, +=, -=, *=, /=, //=, %=, &=, ^=, |=, <<=, >>= | Assignment operators |
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.