What is the output of the following Python code? print(None or 0, 3 and “x”)
Correct answer A. 0 x
Explanation
The and and or operators return one of their operands, not necessarily a bool. x or y returns y when x is falsy, so None or 0 gives 0. x and y returns y when x is truthy, so 3 and "x" gives "x". Expecting True or False here is the usual mistake; only not always returns a bool.
Answer checked How we write and check questions
Discussion