PCEP Operator Precedence and Binding 2 — Questions and Answers
Question 1: What is the result of `2 + 3 * 4 - 1`?
- 13 (Correct answer)
- 19
- 11
- 20
Correct answer: 13
Multiplication is evaluated first (3*4=12), then left-to-right addition and subtraction: 2+12-1=13.
Question 2: Which operator has the highest precedence in Python?
- ** (Correct answer)
- *
- not
- +
Correct answer: **
The exponentiation operator `**` has the highest precedence among arithmetic operators in Python.
Question 3: What does `True or False and False` evaluate to?
- True (Correct answer)
- False
- None
- Error
Correct answer: True
`and` has higher precedence than `or`, so `False and False` is evaluated first (False), then `True or False` equals True.
Question 4: What is the result of `10 // 3 + 1`?
- 4 (Correct answer)
- 3
- 5
- 3.33
Correct answer: 4
Floor division `//` has the same precedence as `*` and `/`, so `10//3=3`, then `3+1=4`.
Question 5: How does Python evaluate `not True and False`?
- False (Correct answer)
- True
- None
- Error
Correct answer: False
`not` has higher precedence than `and`, so `not True` evaluates to False first, then `False and False` equals False.
Question 6: What is the value of `3 ** 2 ** 2`?
- 81 (Correct answer)
- 36
- 12
- 6561
Correct answer: 81
The `**` operator is right-associative, so `2**2=4` is evaluated first, then `3**4=81`.
Question 7: What does `4 + 2 > 3 * 2` evaluate to?
- True (Correct answer)
- False
- 6
- Error
Correct answer: True
Arithmetic operators have higher precedence than comparison operators: `4+2=6` and `3*2=6`, then `6>6` is False — wait, 6>6 is False.
What is the result of `2 + 3 * 4 - 1`?