Practice mode Python

What is the output of the following Python code? print(bool(“False”), bool(“”), bool(0.0))

Correct answer A. True False False

Explanation

Any non-empty string is truthy, whatever its content, so bool("False") is True. The empty string and zero of any numeric type, including 0.0, are falsy. Converting user input such as "False" to a boolean therefore needs an explicit comparison, not 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.