liveBook · Manning

None

As explained in The Quick Python Book, Fourth Edition

None is Python's singleton object representing the absence of a value.

None is Python’s singleton object for an empty or absent value. It serves as a placeholder when meaningful data has not yet been calculated, and all references to it point to the same object. section 4.8

Use None in several common situations:

  • Treat None as false in a Boolean context, alongside zero and empty values; other nonempty, nonzero values are true. section 3.4.1 section 8.11.1
  • Expect a function to return None when it reaches no explicit return statement. An explicit return value is returned instead. section 9.1 section 3.4.6
  • Use None as a placeholder for data that is missing, not yet calculated, or invalid. section 4.8 section 14.2.9

Implicit return and invalid input

A function with no return statement produces None. In spreadsheet-style evaluation, cell_value("bad") can also return None to represent a nonnumeric, nonempty string; safe_apply can return None when evaluating a formula raises TypeError. section 9.1 section 14.2.9

def cell_value(string):
   try:
       return float(string)
   except ValueError:
       if string == "":
           return 0
       else:
           return None

Shows a compact conversion function that returns zero for blank input and None for invalid nonnumeric input. section 14.2.9

def safe_apply(function, x, y, spreadsheet):
   try:
       return function(x, y, spreadsheet)
   except TypeError:
       return None

Shows a wrapper that converts a TypeError during formula evaluation into None. section 14.2.9

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Explains singleton behavior, Boolean falsiness, implicit returns, placeholders, and exception-based invalid-value handling.
Examples
Uses functions without return statements, invalid spreadsheet cells, cell conversion, and safe formula application.
What you can do after
Apply None as a placeholder, recognize implicit function results, and handle invalid values during spreadsheet-style evaluation.
How it connects
Connects None with Boolean expressions, functions, return statements, placeholders, exceptions, and spreadsheet evaluation.

Also explained in

Compare how 4 books explain None →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.