Skip to main content
MahiDev — Learn. Build. Become AI-ready.

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.

Beginner10 min

Visual reference

Null / absent value conceptNull / absent value concept
Empty string vs no valueEmpty string vs no value
Checking for not None in PythonChecking for not None in Python

What you will learn

  • What NoneType and None are
  • Why None is different from 0, False, and ""
  • When to use is None instead of ==
  • Why methods like .clear() return None

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

Passport field = None — not 0, not blank, not False

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:

python
a = None

print(a)
print(type(a))
text
None
<class 'NoneType'>

Important: None is a keyword, like True and False.

python
value = None      # correct
# value = none    # NameError

Your 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
python
print(None == 0)
print(None == "")
print(None == False)
print(None == None)
text
False
False
False
True

Memory trick:

  • 0 → a number
  • False → a boolean
  • "" → an empty string
  • None → no value exists

Chapter 4 — == vs is

Important for interviews and clean code.

Using ==

python
result = None
print(result == None)   # True — works, but not preferred
python
result = None
print(result is None)
text
True

Why is? There is only one None object in Python (a singleton). Identity check is clear and fast.

result → singleton None

Best practice:

python
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.

python
numbers = [1, 2, 3]

x = numbers.clear()

print(numbers)
print(x)
text
[]
None

Why? .clear() empties the same list — it does not need to return a new list.

Same for other mutable collections (from your notes):

python
print(list().clear())
print(set().clear())
print(dict().clear())
text
None
None
None

Common beginner mistake

python
lst = [1, 2, 3]
lst = lst.clear()   # lst becomes None!
print(lst)
text
None

You 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:

python
name = None

2. Optional / missing result:

python
user = None

if user is None:
    print("Login required")

3. Functions with no meaningful return — Python still returns something:

python
def greet():
    print("Hello")

result = greet()
print(result)
text
Hello
None

If a function has no return statement, Python automatically returns None.

Chapter 7 — Truth value of None

In if conditions, None is falsy:

python
if None:
    print("Executed")
else:
    print("Skipped")
text
Skipped

But 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

python
result = None
print(result is None)

2. Observe .clear()

python
data = [10, 20]
value = data.clear()
print(data)
print(value)

3. Placeholder

python
email = None

if email is None:
    print("Email not provided")

Quick knowledge check

  1. How many values does NoneType have?
    One — None.

  2. Is None the same as 0?
    No.

  3. Best way to test for None?
    x is None (and x is not None).

Summary

  • None is the only value of NoneType — absence of a value, not 0 or "".
  • Prefer is None / is not None over == None.
  • In-place mutators like .clear() return None.
  • Functions without return implicitly return None.

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…