HOLIDAY SALE! Save 50% on Membership with code HOLIDAY50. Save 15% on Mentorship with code HOLIDAY15.

6) Variables and Types Lesson

Python Null Value

5 min to complete · By Martin Breuss

Sometimes, you need to express that there just isn't anything there. Sometimes, you need to be able to say that a variable points to something that is just empty:




































Python has its own definition of nothingness. It doesn't look like the empty space above. Instead, it's a special value that is called None.

nothing = None

Python None

None is an indicator of the absence of a value. It's a single pit of nothingness that has its own type, NoneType. There always exists only one such pit of nothingness in each of your Python scripts. Any time you want to define that something is empty, you point to that pit of darkness.

Example of Python None

You might wonder when you'll want to point a variable to nothing. Why make it in the first place? You will see that this comes in handy much more often than you might expect. As an example, think of a situation where you are processing a collection of values that you collected. For example, you might have logged the amount of time you spent working out each day of the week:

day minutes
mon 60
tue 30
wed 0
thu 60
fri 30
sat 30

Well done! You moved nearly every day of the week except for Wednesday. It's okay; you were just really tired on Wednesday.

But wait a moment... what happened on Sunday? You remember Wednesday clearly; you weren't up for your usual workout and skipped it. But what happened on Sunday? Did you do your workout or did you not?

If these are your records from last week, you'll probably figure out what happened on Sunday and fill in the missing value. However, what if this data was collected by someone else? Maybe even years or decades ago? You could make an assumption that no time was spent working out on Sunday and add a row where sun points to 0. But that could be wrong and mess up your statistics. In reality, you don't know whether there was any time spent working out on that Sunday or not.

Colorful illustration of a light bulb

Info: In this example, you are dealing with missing data. You can record that the data is missing by pointing it to Python's pit of nothingness, None

Why Use Python Null Values

By using the None value, you clarify that this data point is missing. It was never recorded, or maybe it got lost somewhere on the way. All that you know is that it's not there.

You might see that, in the context of this example, you can't use 0 to note the absence of a value. 0 is a valid entry in this example that has the specific meaning that you didn't spend any time working out.

Summary: Python Null Value

  • Python null values are expressed with None
  • None is the absence of value. The value of 0 is 0; it has a measurement.
  • None allows you to express that nothing is there. This could be a missed field or incomplete data.