Representing Absence

Sometimes the honest answer is there is no value here. A user skipped their middle name. A search found no match. A function did its job and has nothing to hand back.

Programming needs a way to say nothing, and it's genuinely different from zero, from an empty string, and from false. Zero is a number. An empty string is text with no characters. Nothing is the absence of any value at all.

Intentional absence

PYTHON

middle_name = None

JAVASCRIPT

let middleName = null; 
Compare → Python's None and JavaScript's null both mean the same thing: a deliberate, programmer-chosen 'there is no value here.' This is a SIMILAR CONCEPT: near-perfect equivalents you can translate between freely.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Create a variable for a phone number that hasn't been given yet, set it to None (null in JavaScript), and print it and its type.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: undefined, JavaScript's Extra Flavor →
← Back