The most common reason a Python program prints None is that a function is called for its side effect (such as printing) but its return value is also printed, or a function that is supposed to return a value is missing a return statement, so it implicitly returns None. In short, None appears when you print the result of an expression that evaluates to None — often because a function or method that modifies something in place returns None instead of the modified object.
What None Is and Why It Appears
None is Python's built-in null value. It is a singleton object of type NoneType, used to represent the absence of a value. Every function in Python returns something; if execution reaches the end of the function body without hitting a return statement, the function returns None automatically. This is by design, not an error. When you pass such a function call to print(), Python prints the string representation of None, which is simply None.
For example, consider a function that only prints:
def greet():
print("Hello")
print(greet())
The output is:
Hello
None
The first line comes from the print inside greet. The second line comes from the outer print, which receives the return value of greet() — and that return value is None because there is no return statement.
Common Patterns That Produce None
Several frequent coding patterns lead to unexpected None output. Recognizing them helps you fix the issue quickly.
- Missing return statement: A function that calculates a value but does not return it will yield
Nonewhen called. For instance,def add(a, b): a + breturnsNonebecause the expression is not returned. - Printing the result of an in-place method: Methods like
list.append(),list.sort(),list.reverse(), anddict.update()modify the object in place and returnNone. Writingprint(my_list.append(4))printsNoneand does not print the list. - Using
print()inside a function and then printing the call: As shown above, the inner print outputs the intended text, and the outer print outputsNone. - Assigning the result of a print call:
x = print("hi")assignsNonetox, becauseprint()returnsNone. Later printingxshowsNone. - Functions with a conditional return that falls through: If a function returns a value only inside an
ifbranch and the condition is false, execution reaches the end and returnsNone. - Recursive functions missing a base case return: A recursive function that calls itself but does not return the recursive call's result will return
None.
How to Diagnose the Source of None
When you see None in the output, trace which print call produced it. A systematic approach works well:
- Locate every
print()call in your code, especially those that wrap a function call or method call. - Check whether the wrapped expression is expected to return a value. If it is a function you wrote, verify it has a
returnstatement that returns the intended result. - If the expression is a method known to modify in place (like
appendorsort), remove the surroundingprintand instead print the object after the method call. - Use
type()orrepr()to confirm what is being printed. For example,print(repr(greet()))showsNoneexplicitly, whileprint(type(greet()))shows<class 'NoneType'>. - Insert temporary debug prints or use a debugger to inspect return values at each step.
This process quickly reveals whether the None comes from a missing return, an in-place method, or an unintended assignment.
Fixing Missing Returns and In-Place Methods
If a function is supposed to produce a value, add a return statement. For example, change:
def add(a, b):
a + b
to:
def add(a, b):
return a + b
For in-place methods, separate the method call from the print:
my_list = [3, 1, 2]
my_list.sort()
print(my_list) # prints [1, 2, 3]
Instead of print(my_list.sort()), which prints None. The same applies to append, reverse, extend, insert, remove, clear, and dictionary methods like update and setdefault (though setdefault returns the value, not None, so check the documentation).
When a function both prints and returns, decide on one responsibility. A function that prints is said to have a side effect; a function that returns a value is pure. Mixing them often causes confusion. If you need both, return the value and let the caller print it, or print inside and return nothing, but do not print the call.
None vs. Other Falsy Values
None is not the same as False, 0, '' (empty string), or an empty list. While all are falsy in boolean contexts, only None is the null object. Printing an empty string shows a blank line, not None. Printing False shows False. This distinction matters when debugging: if you see None, the value is specifically the null object, which usually indicates a missing return or an in-place method's return value.
Also, None is a singleton: None == None is True, and the recommended check is is None rather than == None. This is a stylistic convention, but it avoids potential issues with overloaded equality operators.
None in Interactive Sessions and REPL
In an interactive Python session (REPL), the interpreter automatically prints the repr of any expression that evaluates to a non-None value. If an expression evaluates to None, nothing is printed. However, if you explicitly call print() on a None value, you see None. This behavior sometimes surprises beginners who expect the REPL to show None for function calls that return nothing. In scripts, the same rule applies: only explicit print calls produce output.
For example, in the REPL:
>>> def f(): pass
...
>>> f()
>>> print(f())
None
The call f() produces no output, but print(f()) prints None.
Frequently Asked Questions
Why does my function print None even though I have a return statement?
Check whether the return statement is actually executed. If it is inside a conditional branch that is not taken, or after an unconditional return that returns None implicitly, the function may still return None. Also ensure you are not printing the result of a function that returns None by design, such as a function that only prints.
Why does print(my_list.append(4)) show None instead of the list?
The append method modifies the list in place and returns None. So my_list.append(4) returns None, and print prints that None. To see the updated list, call my_list.append(4) on its own line, then print(my_list).
Is None the same as null in other languages?
Conceptually yes, None represents the absence of a value, similar to null in Java or JavaScript, nil in Ruby, or NULL in SQL. However, Python's None is a singleton object, and its behavior in comparisons and type checks differs from some other languages.
How can I avoid accidentally printing None?
Be mindful of what each function returns. If a function is meant to produce a value, ensure it has a return statement. If a method modifies in place, do not wrap it in print. Use a linter or static analysis tool to catch missing returns, and write small tests that assert return values.
Why does my recursive function return None?
A common mistake is to call the recursive function without returning its result. For example, def fact(n): if n == 0: return 1; fact(n-1) * n returns None because the recursive call's result is not returned. The fix is to write return fact(n-1) * n.
Does print return None?
Yes, print() returns None. It is a function that performs output as a side effect and returns nothing. So assigning x = print("hello") sets x to None.