Practice mode Python

According to PEP 8, how should you test whether a variable x refers to None?

Correct answer C. x is None

Explanation

PEP 8 says comparisons to singletons such as None should always use is or is not, never the equality operators. None is a single object, so an identity test is exact, whereas == could be overridden by a class's __eq__ method and give a misleading result.

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.