### Python Quiz: `and` vs `or` — Operand Return Behavior
Test your Python knowledge with these 10 quiz questions, covering truthy/falsy values, short-circuit evaluation, and code output.
Key rule to remember:
* `x and y` → returns `x` if `x` is falsy; otherwise returns `y`.
* `x or y` → returns `x` if `x` is truthy; otherwise returns `y`.
Python and/or Operator Quiz
### Python `and` / `or` Operator Quiz — With Answers
Key rule
* `x and y` → returns `x` if `x` is falsy; otherwise returns `y`.
* `x or y` → returns `x` if `x` is truthy; otherwise returns `y`.
### 10 Quiz Questions with Correct Answers
### Q1. What is the output?
```python
print(0 or 15)
```
A) `0` B) `15` C) `True` D) `False`
Answer: B) `15`
Explanation: `0` is falsy, so `or` returns the second operand, `15`.
### Q2. What is the output?
```python
print("Python" and "Quiz")
```
A) `Python` B) `True` C) `Quiz` D) `False`
Answer: C) `Quiz`
Explanation: `"Python"` is a non-empty string and therefore truthy. The `and` operator returns the second operand.
### Q3. What is the output?
```python
print([] or "Empty")
```
A) `[]` B) `True` C) `False` D) `Empty`
Answer: D) `Empty`
Explanation: An empty list `[]` is falsy, so `or` returns `"Empty"`.
### Q4. What is the output?
```python
print(5 and 0 and 8)
```
A) `0` B) `8` C) `True` D) `5`
Answer: A) `0`
Explanation: `5` is truthy, so evaluation continues. The next operand, `0`, is falsy, so `and` returns `0` immediately.
### Q5. What is the output?
```python
print(None or False or "Done")
```
A) `None` B) `Done` C) `False` D) `True`
Answer: B) `Done`
Explanation: Both `None` and `False` are falsy. The first truthy operand is `"Done"`, which is returned.
### Q6. Select all expressions that evaluate to the integer `0`.
A) `0 and 7` B) `0 or 7` C) `9 and 0` D) `9 or 0`
Answers: A and C
Explanation:
* A) `0 and 7` → `0` because the first operand is falsy.
* B) `0 or 7` → `7` because the first operand is falsy.
* C) `9 and 0` → `0` because `9` is truthy and the second operand is returned.
* D) `9 or 0` → `9` because the first operand is truthy.
### Q7. True or False?
```python
"Hi" or "Bye"
```
evaluates to the string `"Hi"`.
Answer: True
Explanation: `"Hi"` is truthy, so `or` returns the first operand without evaluating the second operand.
### Q8. True or False?
```python
[] and 10
```
evaluates to the integer `10` because `and` always returns its last operand.
Answer: False
Explanation: An empty list is falsy. Therefore, `[] and 10` returns the empty list `[]`, not `10`.
### Q9. What is printed?
```python
def check():
print("called")
return 99
print(1 or check())
```
A) `called`, then `99` B) `99` only C) `called`, then `1` D) `1` only
Answer: D) `1` only
Output:
```text
1
```
Explanation: `1` is truthy, so `or` short-circuits. The function `check()` is never called.
### Q10. What is the output?
```python
value = ""
result = value and 100
print(repr(result))
```
A) `100` B) `False` C) `''` D) `None`
Answer: C) `''`
Explanation: An empty string is falsy, so `and` returns the empty string. `repr()` displays an empty string as `''`.
### Quick Revision Table
| Expression | Result | Reason |
| ------------ | ------ | ----------------------- |
| 0 or 15 | 15 | 0 is falsy |
| 5 and 8 | 8 | 5 is truthy |
| 0 and 8 | 0 | First operand is falsy |
| 5 or 8 | 5 | First operand is truthy |
| [] or "Hi" | "Hi" | Empty list is falsy |
| "" and 100 | "" | Empty string is falsy |
| None or "OK" | "OK" | None is falsy |
Remember: Python's `and` and `or` operators return operands, not necessarily Boolean values. They also use short-circuit evaluation
, so they may skip evaluating later operands.
1. What is the output? print(0 or 15)
A. 0
B. False
C. True
D. 15
2. What is the output? print("Python" and "Quiz")
A. Python
B. False
C. Quiz
D. True
3. What is the output? print([] or "Empty")
A. Empty
B. True
C. []
D. False
4. What is the output? print(5 and 0 and 8)
A. True
B. 0
C. 5
D. 8
5. What is the output? print(None or False or "Done")
A. True
B. None
C. False
D. Done
6. Select every expression that evaluates to the integer 0. # Evaluate each expression independently
A. 9 or 0
B. 9 and 0
C. 0 and 7
D. 0 or 7
7. In Python, the expression "Hi" or "Bye" evaluates to the string "Hi".
True
False
8. In Python, [] and 10 evaluates to the integer 10 because and always returns its last operand.
True
False
9. What is printed? def check(): print("called") return 99 print(1 or check())
A. called, then 1
B. called, then 99
C. 99 only
D. 1 only
10. What is the output? value = "" result = value and 100 print(repr(result))
A. None
B. ''
C. 100
D. False
Quick revision tip: `and` stops at the first falsy operand; `or` stops at the first truthy operand. Both return the actual operand,
not necessarily `True` or `False`.