Practice mode Python

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.