How it works
None is not an empty string, zero or False. All are falsy in a condition, but each can carry different meaning. For example, a score of zero is known; a score of None can mean it has not been entered.
A function that reaches its end without returning a value returns None. list.append() also returns None because it changes the list in place. Assigning items = items.append(value) therefore loses the list binding.
None can mark an omitted optional argument. For a mutable default, create a new list or dictionary inside the function when the argument is None, rather than sharing a mutable object created in the function definition.
Common mistakes and boundaries
Use identity rather than == None, because custom equality methods may have other behaviour. This is about a clear sentinel check, not a performance claim.
dict.get(key) returns None by default both for a missing key and a key explicitly holding None. Use key in mapping when that distinction matters.
Try it yourself
Make a dictionary containing a score of zero and a separate score of None. Display zero normally and show “not entered” only for None. Test a missing key as a third case.
Syntax
variable = NoneExamples
Initializing a Variable
Using None as a placeholder before a real value is available.
user = None
print(user) # None
# Later in the program, assign a real value
user = "Alice"
print(user) # Alice- The initial binding means the user is not yet known. Reassignment later supplies a concrete name.
- Expected output: None Alice
Default Parameter Value
Using None as a safe default for mutable or optional parameters.
def greet(name=None):
if name is None:
print("Hello, stranger!")
else:
print(f"Hello, {name}!")
greet() # Hello, stranger!
greet("Priya") # Hello, Priya!- The omitted argument receives None and selects the fallback; an explicit name selects the greeting branch.
- Expected output: Hello, stranger! Hello, Priya!
Checking for None
Using 'is' and 'is not' to test for None, the recommended way instead of equality operators.
result = None
if result is None:
print("No result yet")
data = {"name": "John"}
value = data.get("age") # key doesn't exist
if value is not None:
print(f"Age: {value}")
else:
print("Age not provided")- Identity checks distinguish a missing result. get returns its default None for the absent age key.
- Expected output: No result yet Age not provided
Implicit Return Value
A function with no return statement (or a bare return) implicitly returns None.
def log_message(msg):
print(f"LOG: {msg}")
# no return statement
result = log_message("Server started")
print(result) # None- The function prints a log line but does not return a value, so the caller receives and prints None.
- Expected output: LOG: Server started None
Best practices
- Use is None or is not None to check the sentinel without invoking custom equality behaviour.
- Use None as a default argument for optional parameters instead of mutable defaults like [] or {}, which are evaluated only once and shared across calls
- Remember that dict.get() returns None by default when a key is missing, rather than raising an error like square-bracket access does
- Don't confuse None with False, 0, or an empty string/list - they are all falsy in a boolean context but are not the same value
- Use None to represent "not yet known" or "not applicable", and reserve empty collections for "known to be empty"
Runtime & versions
Python interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Python language reference