Lesson 14
NoneType — The `None` Value
Learn what None really means in Python, how it differs from 0, False, and empty values, and why many built-in methods return None.
Visual reference
What you will learn
- What
NoneTypeandNoneare - Why
Noneis different from0,False, and"" - When to use
is Noneinstead of== - Why methods like
.clear()returnNone
Chapter 1 — What is None?
None is the only value of the NoneType data type.
Purpose (your notes): represent nothing — not False, not a space, not 0. It is not a number or string; it means no value exists (placeholder or “no result”).
NoneType is a pre-defined class, but you do not call NoneType() in normal code — use the keyword None.
Real-life analogy: application form
The passport field is not zero, not an empty string — it simply has no value yet.
Chapter 2 — Creating a None value
Assign None directly:
a = None
print(a)
print(type(a))None
<class 'NoneType'>Important: None is a keyword, like True and False.
value = None # correct
# value = none # NameErrorYour notes: we cannot create another NoneType instance with NoneType() — NameError: name 'NoneType' is not defined in the REPL unless you import or use type(None).
Chapter 3 — None vs 0 vs False vs ""
These are not the same.
| Expression | Result |
|---|---|
None == 0 |
False |
None == False |
False |
None == "" |
False |
None == None |
True |
print(None == 0)
print(None == "")
print(None == False)
print(None == None)False
False
False
TrueMemory trick:
0→ a numberFalse→ a boolean""→ an empty stringNone→ no value exists
Chapter 4 — == vs is
Important for interviews and clean code.
Using ==
result = None
print(result == None) # True — works, but not preferredUsing is (recommended)
result = None
print(result is None)TrueWhy is? There is only one None object in Python (a singleton). Identity check is clear and fast.
Best practice:
if result is None:
print("No value")
if result is not None:
print("Has a value")Chapter 5 — Methods that return None
Some methods change the object in place and return None instead of a new collection.
numbers = [1, 2, 3]
x = numbers.clear()
print(numbers)
print(x)[]
NoneWhy? .clear() empties the same list — it does not need to return a new list.
Same for other mutable collections (from your notes):
print(list().clear())
print(set().clear())
print(dict().clear())None
None
NoneCommon beginner mistake
lst = [1, 2, 3]
lst = lst.clear() # lst becomes None!
print(lst)NoneYou replaced the list with the return value of .clear(), which is always None.
Chapter 6 — When do we use None?
1. Placeholder — value assigned later:
name = None2. Optional / missing result:
user = None
if user is None:
print("Login required")3. Functions with no meaningful return — Python still returns something:
def greet():
print("Hello")
result = greet()
print(result)Hello
NoneIf a function has no return statement, Python automatically returns None.
Chapter 7 — Truth value of None
In if conditions, None is falsy:
if None:
print("Executed")
else:
print("Skipped")SkippedBut falsy is not the same as equal to False:
| Expression | Result |
|---|---|
if None: |
treated as False (skipped) |
None == False |
False |
None is falsy, but it is not the boolean False.
Practice exercises
1. Check for None
result = None
print(result is None)2. Observe .clear()
data = [10, 20]
value = data.clear()
print(data)
print(value)3. Placeholder
email = None
if email is None:
print("Email not provided")Quick knowledge check
-
How many values does
NoneTypehave?
One —None. -
Is
Nonethe same as0?
No. -
Best way to test for
None?
x is None(andx is not None).
Summary
Noneis the only value ofNoneType— absence of a value, not0or"".- Prefer
is None/is not Noneover== None. - In-place mutators like
.clear()returnNone. - Functions without
returnimplicitly returnNone.
Module complete
You have worked through all 14 built-in data types in this module: from int through dict to None.
Next in the learning path: Type casting and fundamental conversions (int(), float(), str(), bool(), and related topics) — when that module is published on MahiDev.
Loading playground…