liveBook · Manning

None

As explained in Tiny Python Projects: Learn coding and testing with puzzles and games

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

None is Python’s singleton value for the absence of a meaningful value. It commonly appears when an operation changes an object in place but has no useful result to return. section 3.3.7 section 16.1.4

Recognize None in several common situations:

  • list.sort() and random.shuffle() modify their arguments in place and return None; assigning the result replaces the useful object with None. section 3.3.7 section 16.1.4
  • A function with no explicit return produces None, which can represent an absent result such as no Tic-Tac-Toe winner. section 21.2.3
  • argparse can use None as the default when optional inputs are omitted, so code must not assume the value is a list. section 17.3

Avoid replacing a list with None

>>> items = ['soda', 'sammiches', 'chips', 'ice cream'] >>> items = items.sort() >>> type(items) <class 'NoneType'> Call items.sort() by itself when you want to mutate the existing list. Use sorted(items) when you need a new sorted list. section 3.3.7

Use None as a missing result

winner = find_winner(board) print(f'{winner} has won!' if winner else 'No winner.') When find_winner() reaches the end without returning a player, its result is None and the conditional reports no winner. section 21.2.3

>>> type(items)
<class 'NoneType'>

Inspecting the assigned value and its type makes the in-place operation’s None return visible. section 3.3.7

How Tiny Python Projects: Learn coding and testing with puzzles and games covers it

How deep it goes
Explains None through list mutation, randomization, omitted arguments, and implicit returns, without descending into object internals.
Examples
Demonstrates None with list.sort(), random.shuffle(), omitted argparse inputs, and a Tic-Tac-Toe winner search.
What it assumes
Assumes familiarity with Python lists, functions, conditionals, and command-line argument parsing.
What you can do after
Diagnose accidental None assignments and interpret None as a deliberate absence signal in command-line programs and functions.
How it connects
Connects None with in-place mutation, function return values, argparse defaults, iterators, and conditional result handling.

Also explained in

Compare how 4 books explain None →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny Python Projects: Learn coding and testing with puzzles and games. The section links point to the parts of the book it draws on.