None & NoneType
None is Python's special constant that represents the deliberate absence of a value — the single instance of a type called NoneType that means "nothing here".
Learn None & NoneType in our free Python course — an interactive lesson with runnable examples, a practice exercise and a quick reference.
Part of the free Python course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
You'll meet None everywhere: as the default return of a function, as a "not found" signal, and as the safe sentinel that fixes one of Python's most infamous beginner traps.
None is not zero, not an empty string, and not False — it's a distinct object meaning "no value at all". It's the only value of type NoneType :
Reach for None whenever you need to say "this slot is intentionally empty" — a result not computed yet, a search that found nothing, or an optional setting left unset.
Because there is exactly one None in the whole program, the right way to check for it is identity ( is ), not equality ( == ):
If a function has no return (or a bare return ), it hands back None . Methods that change an object in place do this too — and that causes a famous bug:
Default values are created once, at definition time — so a default list is reused across every call and leaks data between them:
✅ The fix: default to None, build fresh inside
The None sentinel pattern — default to None , then replace it inside the function — is the standard cure for mutable defaults like [] and {' '} .
Replace each ___ to fix the mutable default and the None checks so the output matches.
❌ Reassigning the result of an in-place method
✅ Either call names.sort() on its own, or use names = sorted(names) to get a new sorted list.
✅ Guard first: if user is not None: user.upper() . A "NoneType has no attribute" error usually means an earlier step returned None .
✅ Default to None and build the dict inside: if data is None: data = .
Write a function that caches results, using the None sentinel so each fresh call starts clean.
Go deeper with the official Python documentation:
Lesson complete — None holds no surprises now!
You know None is the absence of a value, you test it with is None , you understand the default-return and in-place-method traps, and you can wield the None sentinel to defeat mutable default arguments.
🚀 Up next: Conditional Expressions (Ternary) — pick between two values in a single tidy line.
Practice quiz
What does None represent in Python?
- The number zero
- The deliberate absence of a value
- An empty string
- A boolean False
Answer: The deliberate absence of a value. None is a distinct object meaning 'no value at all' — it is not 0, '', or False. It is the sole instance of NoneType.
What is the type of None?
- bool
- int
- NoneType
- object
Answer: NoneType. type(None) is <class 'NoneType'>; None is the single value of that type.
Why is 'value is None' preferred over 'value == None'?
- It is shorter to type
- None is a unique singleton, so identity (is) is correct, fastest, and immune to overridden __eq__
- == does not work on None
- PEP 8 forbids 'is'
Answer: None is a unique singleton, so identity (is) is correct, fastest, and immune to overridden __eq__. Because there is only one None object, identity (is) is the correct and safe check; == could be fooled by a class overriding __eq__. PEP 8 recommends 'is None'.
What does a function with no return statement return?
- 0
- An empty string
- None
- It raises an error
Answer: None. A function with no return (or a bare return) automatically returns None.
What does None == 0 evaluate to?
- True
- False
- None
- It raises an error
Answer: False. None is not equal to 0, '', or False — None == 0 is False, even though None is itself falsy.
What is wrong with writing 'nums = nums.sort()'?
- sort() is too slow
- sort() mutates in place and returns None, so nums becomes None
- sort() does not exist on lists
- It sorts in reverse
Answer: sort() mutates in place and returns None, so nums becomes None. list.sort() sorts in place and returns None, so reassigning sets nums to None. Either call nums.sort() alone, or use sorted(nums).
What does list.append() return?
- The new list
- The appended item
- None
- The list length
Answer: None. append() mutates the list in place and returns None — like other in-place methods such as sort() and reverse().
Why is 'def f(items=[])' a dangerous default argument?
- Lists cannot be defaults
- The same list is created once and reused across all calls, leaking data between them
- It is slower than a tuple
- items is undefined
Answer: The same list is created once and reused across all calls, leaking data between them. Default values are created once at definition time, so a default list is shared across every call and accumulates data between them.
What is the standard fix for a mutable default argument?
- Use an empty tuple
The None sentinel pattern — default to None and build a fresh list/dict inside the function — gives each call its own object.
Calling a method on a None value, like user.upper() when user is None, raises what?
- TypeError
- ValueError
- AttributeError: 'NoneType' object has no attribute 'upper'
- Nothing — it returns None
Answer: AttributeError: 'NoneType' object has no attribute 'upper'. None has no such method, so you get AttributeError. This usually means an earlier step unexpectedly returned None.