Operators and Expressions Flashcards
7 cards from real Python practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 7 Operators and Expressions flashcards as text
What is the result of `10 % 3` in Python?
Answer: 1
The modulo operator `%` returns the remainder of division; `10 ÷ 3 = 3` remainder `1`.
What does `x = []; x or 'default'` return?
Answer: 'default'
An empty list is falsy in Python, so `[] or 'default'` returns `'default'` because the `or` operator returns the first truthy value.
Which of the following is a valid augmented assignment operator in Python?
Answer: //=
`//=` is valid and performs in-place floor division; the others are not valid Python operators.
What is the result of `'5' + 5` in Python?
Answer: Raises a TypeError
Python does not support implicit type coercion between strings and integers; attempting `'5' + 5` raises a `TypeError`.
What does the expression `any([False, 0, '', None, 1])` return?
Answer: True
`any()` returns `True` if at least one element is truthy; since `1` is truthy, the result is `True`.
What is the result of `3 != 3` in Python?
Answer: False
The `!=` operator returns `True` when the operands are not equal; since `3 == 3`, `3 != 3` evaluates to `False`.
What does `all([True, 1, 'hello', [1]])` return?
Answer: True
`all()` returns `True` only if every element is truthy; all elements (`True`, `1`, `'hello'`, `[1]`) are truthy, so the result is `True`.