Python Operators and Expressions 5 โ Questions and Answers
Question 1: What is the result of `10 % 3` in Python?
- 1 (Correct answer)
- 3
- 0
- 0.333
Correct answer: 1
The modulo operator `%` returns the remainder of division; `10 รท 3 = 3` remainder `1`.
Question 2: What does `x = []; x or 'default'` return?
- 'default' (Correct answer)
- []
- True
- False
Correct answer: 'default'
An empty list is falsy in Python, so `[] or 'default'` returns `'default'` because the `or` operator returns the first truthy value.
Question 3: Which of the following is a valid augmented assignment operator in Python?
- //= (Correct answer)
- ==+
- **+
- ++=
Correct answer: //=
`//=` is valid and performs in-place floor division; the others are not valid Python operators.
Question 4: What is the result of `'5' + 5` in Python?
- Raises a TypeError (Correct answer)
- '55'
- 10
- '5 + 5'
Correct answer: Raises a TypeError
Python does not support implicit type coercion between strings and integers; attempting `'5' + 5` raises a `TypeError`.
Question 5: What does the expression `any([False, 0, '', None, 1])` return?
- True (Correct answer)
- False
- 1
- None
Correct answer: True
`any()` returns `True` if at least one element is truthy; since `1` is truthy, the result is `True`.
Question 6: What is the result of `3 != 3` in Python?
- False (Correct answer)
- True
- 0
- None
Correct answer: False
The `!=` operator returns `True` when the operands are not equal; since `3 == 3`, `3 != 3` evaluates to `False`.
Question 7: What does `all([True, 1, 'hello', [1]])` return?
- True (Correct answer)
- False
- 1
- Raises a TypeError
Correct answer: True
`all()` returns `True` only if every element is truthy; all elements (`True`, `1`, `'hello'`, `[1]`) are truthy, so the result is `True`.
What is the result of `10 % 3` in Python?