liveBook · Manning

None

As explained in Get Programming: Learn to code with Python

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

None is Python’s special value for the absence of a value. For example, a new pet may not have a name yet. None is an object with the type NoneType; it is different from the string "None". section 5.2

Functions use None when they finish without an explicit return statement. A function may print a message for the user while still returning None to the code that called it. section 21.2

Printing versus returning

In the example, say_name("Dora") prints Dora but produces no visible returned result. show_kid("Ellie") prints nothing because it only returns a value. print(say_name("Frank")) prints Frank and then None, while print(show_kid("Gus")) prints Gus. The function call supplies None in the first case because say_name has no return statement. section 21.2

Listing 21.5. Function with and without a return
def say_name(kid):                    #1
    print(kid)                        #2

def show_kid(kid):                    #3
    return kid                        #4

say_name("Dora")                      #5
show_kid("Ellie")                     #6
print(say_name("Frank"))              #7
print(show_kid("Gus"))                #8

Compare a function that prints with one that returns, then trace what appears when each call is made directly or passed to print. section 21.2

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains None’s type, distinguishes it from "None", and traces its appearance when functions print or return values.
Examples
Uses an unnamed pet, type-identification checks, and say_name/show_kid calls to demonstrate absent values and implicit returns.
What it assumes
Assumes basic Python values and introduces None and NoneType directly from the absence-of-a-value idea.
What you can do after
Evaluate/understand whether a function prints a value, returns a value, or supplies None automatically.
How it connects
Connects None with Python objects, NoneType, functions, return statements, and print statements.

Also explained in

Compare how 4 books explain None →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.