MemotivaCommon pitfalls and best practices

What is the difference between equals and is for None comparisons?

Common pitfalls and best practices

Audio flashcard · 0:12

Nortren·

What is the difference between equals and is for None comparisons?

0:12

Always use is None or is not None to check for None. Equality with None can be misleading because a custom dunder eq could return true for non-None values. None is a singleton, so identity comparison is the correct and idiomatic check.
peps.python.org