Skip to main content

8.2) None Type


You can assign an object the value None, with a capital N.

>>> A=None
>>> type(A)
<type 'NoneType'>

The type NoneType can only take the value None. You can test whether a variable has the value None with:

>>> A is None # equivalent to A == None
True

You can’t do operations mixing numbers and None in Python, it will return an error. For example:

>>> None +32.4
Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    A+32.4
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'