The None TypeΒΆ
Python provides a special value called None
that is used to indicate the absence of a value. In the cell below, we create a variable storing a value of None
. We then print this variable, as well as its type.
empty_var = None
print(empty_var)
print(type(empty_var))
None
<class 'NoneType'>
One situation in which you might encounter None
is if you attempt to assign to a variable the output (or return value) of a function that does not actually produce any output. The print()
function, for example, performs an action by displaying text to the screen, but does not actually return any values. We see this in the next cell, in which we attempt to store the output of print()
into a variable, and then print the value of this variable to confirm that is is None
.
my_output = print('Hello')
print(my_output)
Hello
None
We will discuss return values of functions and the None
value further in later lessons.