Identify the correct output of the following Python Command: print (10 or 40)
2023
Identify the correct output of the following Python Command: print (10 or 40)
- A.
10 / 10
- B.
40 / 40
- C.
50 / 50
- D.
400 / 400
Attempted by 1792 students.
Show answer & explanation
Correct answer: A
Answer: 10
Explanation: In Python, the boolean operator or returns the first operand that is truthy; if the first operand is falsy, it returns the second.
Both 10 and 40 are nonzero integers, so both are truthy.
The or operator evaluates the left operand first; since 10 is truthy, it returns 10 without evaluating the second operand.
Therefore, print(10 or 40) prints 10.
Note: If the first operand were falsy (for example 0), then or would return the second operand, e.g. print(0 or 40) prints 40.