Skip to content

Computer Science · Ch 5 — Getting Started with Python

None

5.7.4

None

None is a special data type with a single value. It is used to signify the absence of value in a situation — a variable that exists but deliberately holds "nothing yet" can be given the value None.

Two properties define it:

  • None supports no special operations. There is nothing to add, index or iterate; it is purely a marker.
  • None is neither the same as False nor the same as 0 (zero). Although all three can feel like "nothing", they are distinct values of distinct types — False is a boolean, 0 is an integer, and None is the sole value of its own type.

None in the interpreter

The textbook's Example 5.7:

>>> myVar = None
>>> print(type(myVar))
<class 'NoneType'>
>>> print(myVar)
None

The type check reveals the name of None's type: NoneType, of which None is the only value. Printing the variable displays the word None itself.

When it is useful …