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



