Operator Precedence and Binding Flashcards
7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Operator Precedence and Binding flashcards as text
What does `1 + 2 ** 3 * 4` evaluate to?
Answer: 33
Precedence order: `2**3=8` first, then `8*4=32`, then `1+32=33`.
Which of the following has the LOWEST precedence in Python?
Answer: or
Among logical operators and comparisons, `or` has the lowest precedence, evaluated last.
What is the result of `10 - 3 + 2 * 2`?
Answer: 11
`2*2=4` first (higher precedence), then left-to-right: `10-3+4 = 7+4 = 11`.
What does `True and not False` evaluate to?
Answer: True
`not` has higher precedence than `and`: `not False=True` first, then `True and True = True`.
What is the output of `print(2 * 3 ** 2)`?
Answer: 18
`**` has higher precedence than `*`: `3**2=9` first, then `2*9=18`.
What is the value of `(2 + 3) * (4 - 1) ** 2`?
Answer: 45
Parentheses first: `(2+3)=5` and `(4-1)=3`; then `**`: `3**2=9`; then `*`: `5*9=45`.
In Python, what is the associativity of the assignment operator `=`?
Answer: Right
The assignment operator is right-associative: `a = b = 5` is evaluated as `a = (b = 5)`.