The logic of the None object

In Chapter 2, Simple Data Types, we introduced the None object. It is a unique, immutable object, often used to indicate that a parameter should have a default value or that an input is not available. Some languages have a special null object or null pointer that have similar semantics to the Python None object.

The None object has no arithmetic operators defined. It's equivalent to False. The == and != operators are generally defined for None. However, these operators aren't always appropriate because other objects might exhibit similar behavior.

Generally, we'll use the is comparison when trying to determine if a variable is set to None. The == test can be redefined by a class that implements the __eq__ special method; ...

Get Python Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.