Python's None is the language's built-in way of representing nothing. It is not zero, it is not an empty string, and it is not False, though it is falsy in a boolean context. None is the sole instance of the NoneType class, and it exists to give programmers a clear, unambiguous way to say that a variable has no meaningful value right now. Every Python function that does not explicitly return a value returns None by default. Every variable that you want to initialize but not yet assign a meaningful value to should start as None. Understanding when and how to use None separates code that handles missing data gracefully from code that crashes unexpectedly.
If you have read the overview of Python data types and the article on the boolean data type, you know that None is falsy but distinct from False. This article explains why that distinction matters and how to use None correctly in your own code.
What None is and what it is not
None is a singleton, which means there is exactly one None object in the entire Python runtime. Every variable you set to None, every function that returns None, and every default argument you leave as None all point to the exact same object in memory. This is why the is operator is the correct way to check for None: there is only one None to check against, and identity comparison cannot be overridden by custom object methods the way equality comparison can.
None is not the same as zero. A variable set to 0 holds a meaningful numeric value. None means the variable has no value at all. None is not the same as an empty string. An empty string is a valid piece of text with zero characters. None means there is no text to work with. In data processing, this distinction matters because treating None as zero could silently produce incorrect calculations, and treating None as an empty string could hide missing data that should have been flagged:
value = None
if value is None:
print("No value assigned yet")
if value:
print("This will never print because None is falsy")The first check is the idiomatic Python pattern that you will see in every professional codebase. The second check also skips the block because None is falsy, but it is less precise because it would also skip the block if value were 0, an empty string, or an empty list. When you specifically need to know whether a value is missing rather than merely falsy, the is None check is the right tool.
Where None appears automatically
Python uses None as the default return value for every function that does not have an explicit return statement. If you write a function that prints output, modifies a mutable argument, or writes to a file without returning anything, that function implicitly returns None. Assigning its result to a variable stores None, which can cause bugs if you later try to use that variable as if it held a meaningful return value.
Dictionary lookups with the get method return None by default when the key is not found, which is a safer pattern than using square brackets and catching a KeyError. Object attributes that have not been set return None when accessed through getattr with a default, and many library functions return None to signal that an operation found no results or that a search reached the end of its data.
None as a sentinel value
A sentinel is a special value that signals a specific condition, and None is Python's built-in sentinel for missing or unspecified data. The most common use is in function default arguments where the actual default value is mutable. Python evaluates default arguments once at function definition time, so using an empty list as a default would share that list across all calls. Using None as the default and creating the mutable object inside the function avoids this entirely.
def add_item(item, target=None):
if target is None:
target = []
target.append(item)
return targetThis pattern appears in nearly every Python codebase that defines functions with mutable defaults, and you will recognize it immediately once you know to look for it.
None also serves as a sentinel when iterating through data that may have gaps. If a function that looks up a value in a database or an API cannot find a result, returning None lets the caller distinguish between "found a falsy value" and "found nothing at all." This pattern appears in every codebase that handles external data.
Common None pitfalls
The most common None mistake is calling a method on a variable that unexpectedly holds None. If a function returns None when a lookup fails and you immediately try to call a method on the result, Python raises an AttributeError because NoneType has virtually no methods. Defensive code checks for None before using the value or uses a conditional expression to provide a fallback.
Another common mistake is confusing a general falsiness check with a specific None check. The expression "if not value" catches all falsy values including zero, empty strings, and empty lists, which might be valid data in your program. The expression "if value is None" only catches None. Use the broader check when any falsy value should trigger the same behavior. Use the specific None check when only missing data, and not zero or empty containers, should take the special path.
Rune AI
Key Insights
- None is a singleton of type NoneType representing the absence of a value.
- Always check for None with
is None, not== None. - Use None as the default argument value when the actual default is mutable.
- Functions without a return statement implicitly return None.
- None is falsy, but
is Noneis more specific thannot value. - None is not equal to 0, False, or empty strings; it is a distinct type.
Frequently Asked Questions
Is None the same as False, 0, or an empty string?
Why should I use `is None` instead of `== None`?
How do I use None as a default function argument correctly?
Conclusion
None is Python's way of saying 'no value here,' and using it correctly, checking with is, using it as a sentinel default, and distinguishing it from other falsy values, makes your code clearer and avoids bugs that arise from confusing absence with emptiness or zero.
More in this topic
Create and Assign Variables in Python
Learn every way to create and assign variables in Python, from basic single assignment to expressions, type hints, and practical patterns beginners use every day.
Python Variable Naming Rules
Learn Python's variable naming rules, including allowed characters, reserved keywords, PEP 8 conventions, and how to choose names that make your code readable.
Python Variables Explained
Understand what Python variables are, how they store and reference data, and why Python's variable model is different from other programming languages.