Skip to content
Foxipa

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.

Learning

Python None and NoneType

Understand Python's None value, what NoneType means, how functions produce None, and how to test for the absence of a value.

Levels: Beginner ~12 min read

Basic

Python uses None for a value that represents the absence of a value in many situations. None is not the same thing as zero, an empty string, or False.

There is one None object. The built-in name points to that object, and its type is NoneType.

None is its own value and type

None is the sole instance of NoneType. You normally use the name None directly rather than constructing a value of this type.

Interactive Runnable example
Edit

Ready to run.

Functions can produce None

A function that reaches the end without a return value returns None. An explicit return None makes the same result visible in the source code.

Interactive Runnable example
Edit

Ready to run.

None is different from an empty value

An empty string, empty list, and zero are real values with their own types. None instead communicates that there is no value in the role where the value would normally appear.

Interactive Runnable example
Edit

Ready to run.

Check for None with identity

When the question is specifically whether a value is None, write value is None or value is not None. This expresses the identity test directly.

Interactive Runnable example
Edit

Ready to run.

None is false in a Boolean context

The truth-value of None is false. That does not mean every false value is None. Use an identity test when you need to distinguish missing data from other false values.

Interactive Runnable example
Edit

Ready to run.

None often marks an absent result

A program can use None to mean that a result, setting, or piece of information is not available. The surrounding program decides what that absence means; None itself does not describe why the value is absent.

Interactive Runnable example
Edit

Ready to run.

Key idea

Use None when you need one clear value to represent absence, and use is None when the distinction matters.

Was this page helpful?

Mark this learning resource complete to track your learning progress.