On the actual behavior, there is no difference. They all return None and that's it. However, there is a time and place for all of these. The following instructions are basically how the different methods should be used (or at least how I was taught they should be used), but they are not absolute rules so you can mix them up if you feel necessary to.

Using return None

This tells that the function is indeed meant to return a value for later use, and in this case it returns None. This value None can then be used elsewhere. return None is never used if there are no other possible return values from the function.

In the following example, we return person's mother if the person given is a human. If it's not a human, we return None since the person doesn't have a mother (let's suppose it's not an animal or something).

def get_mother(person):
    if is_human(person):
        return person.mother
    else:
        return None

Using return

This is used for the same reason as break in loops. The return value doesn't matter and you only want to exit the whole function. It's extremely useful in some places, even though you don't need it that often.

We've got 15 prisoners and we know one of them has a knife. We loop through each prisoner one by one to check if they have a knife. If we hit the person with a knife, we can just exit the function because we know there's only one knife and no reason the check rest of the prisoners. If we don't find the prisoner with a knife, we raise an alert. This could be done in many different ways and using return is probably not even the best way, but it's just an example to show how to use return for exiting a function.

def find_prisoner_with_knife(prisoners):
    for prisoner in prisoners:
        if "knife" in prisoner.items:
            prisoner.move_to_inquisition()
            return # no need to check rest of the prisoners nor raise an alert
    raise_alert()

Note: You should never do var = find_prisoner_with_knife(), since the return value is not meant to be caught.

Using no return at all

This will also return None, but that value is not meant to be used or caught. It simply means that the function ended successfully. It's basically the same as return in void functions in languages such as C++ or Java.

In the following example, we set person's mother's name and then the function exits after completing successfully.

def set_mother(person, mother):
    if is_human(person):
        person.mother = mother

Note: You should never do var = set_mother(my_person, my_mother), since the return value is not meant to be caught.

Answer from user2032433 on Stack Overflow
Top answer
1 of 5
787

On the actual behavior, there is no difference. They all return None and that's it. However, there is a time and place for all of these. The following instructions are basically how the different methods should be used (or at least how I was taught they should be used), but they are not absolute rules so you can mix them up if you feel necessary to.

Using return None

This tells that the function is indeed meant to return a value for later use, and in this case it returns None. This value None can then be used elsewhere. return None is never used if there are no other possible return values from the function.

In the following example, we return person's mother if the person given is a human. If it's not a human, we return None since the person doesn't have a mother (let's suppose it's not an animal or something).

def get_mother(person):
    if is_human(person):
        return person.mother
    else:
        return None

Using return

This is used for the same reason as break in loops. The return value doesn't matter and you only want to exit the whole function. It's extremely useful in some places, even though you don't need it that often.

We've got 15 prisoners and we know one of them has a knife. We loop through each prisoner one by one to check if they have a knife. If we hit the person with a knife, we can just exit the function because we know there's only one knife and no reason the check rest of the prisoners. If we don't find the prisoner with a knife, we raise an alert. This could be done in many different ways and using return is probably not even the best way, but it's just an example to show how to use return for exiting a function.

def find_prisoner_with_knife(prisoners):
    for prisoner in prisoners:
        if "knife" in prisoner.items:
            prisoner.move_to_inquisition()
            return # no need to check rest of the prisoners nor raise an alert
    raise_alert()

Note: You should never do var = find_prisoner_with_knife(), since the return value is not meant to be caught.

Using no return at all

This will also return None, but that value is not meant to be used or caught. It simply means that the function ended successfully. It's basically the same as return in void functions in languages such as C++ or Java.

In the following example, we set person's mother's name and then the function exits after completing successfully.

def set_mother(person, mother):
    if is_human(person):
        person.mother = mother

Note: You should never do var = set_mother(my_person, my_mother), since the return value is not meant to be caught.

2 of 5
57

Yes, they are all the same.

We can review the interpreted machine code to confirm that that they're all doing the exact same thing.

import dis

def f1():
  print "Hello World"
  return None

def f2():
  print "Hello World"
  return

def f3():
  print "Hello World"

dis.dis(f1)
    4   0 LOAD_CONST    1 ('Hello World')
        3 PRINT_ITEM
        4 PRINT_NEWLINE

    5   5 LOAD_CONST    0 (None)
        8 RETURN_VALUE

dis.dis(f2)
    9   0 LOAD_CONST    1 ('Hello World')
        3 PRINT_ITEM
        4 PRINT_NEWLINE

    10  5 LOAD_CONST    0 (None)
        8 RETURN_VALUE

dis.dis(f3)
    14  0 LOAD_CONST    1 ('Hello World')
        3 PRINT_ITEM
        4 PRINT_NEWLINE            
        5 LOAD_CONST    0 (None)
        8 RETURN_VALUE      
🌐
Reddit
reddit.com › r/learnpython › eli5 how does "none" work exactly?
r/learnpython on Reddit: ELI5 how does "None" work exactly?
October 6, 2023 -

I get the general idea that None is a type when there is no specific value to be return.

But I am just confused on how to explicitly have a value of "None" . I am still learning python so I want to understand in which case does a function returns the value of "None". Like, it would also be helpful is someone could share a short function that displays "None" , preferably with no "return".

I've search online and there was an example of print(print("hi")), I kind of get this, the interpreter displays the first print and the second one is "None" because there is no value.

Thanks in advance

🌐
Real Python
realpython.com › python-return-statement
The Python return Statement: Usage and Best Practices – Real Python
June 14, 2024 - If you don’t supply an explicit return statement with an explicit return value, then Python will supply an implicit return statement using None as a return value. In the above example, add_one() adds 1 to x and stores the value in result but it doesn’t return result. That’s why you get value = None instead of value = 6. To fix the problem, you need to either return result or directly return x + 1. An example of a function that returns None is print().
🌐
Julianhysi
julianhysi.com › post › 4
Julian's Blog - Bare return vs return None vs no return
Every function in Python which does not hit a return statement, will implicitly return None.
🌐
Python.org
discuss.python.org › python help
Why does one version of my function return None, while the other works fine? - Python Help - Discussions on Python.org
October 26, 2023 - Inspired by the pipeline operator (|>) in other languages, I tried to implement a function to imitate it. When I use reduce to implement it, it results in None somewhere along the way, but another one using loops works just fine. from functools import partial, reduce from pprint import pprint def pipeline(data, *funcs): res = data for func in funcs: res = func(res) return res def pipeline_v2(data, *funcs): reduce(lambda arg, func: func(arg), funcs, data) def main() ->...
🌐
Quora
quora.com › What-does-it-mean-when-the-Python-function-returns-none
What does it mean when the Python function returns none? - Quora
Answer (1 of 6): There are no inherently implied semantics attached to None-returning functions. In other words, it means whatever you want it to mean. In Python, interpreted and dynamically typed as it is, functions don't have return types. There is no type checker to enforce that a function re...
🌐
Better Programming
betterprogramming.pub › please-stop-returning-none-from-python-functions-ff98e492b4b0
Stop Returning None From Python Functions | by Imran Ali | Better ...
August 10, 2023 - The function returns None when the denominator is 0. This makes sense as the result is undefined so sending None sounds natural. However, the user of the function can incorrectly use it as shown below.
Find elsewhere
🌐
Quora
quora.com › In-Python-what-does-return-None-mean-if-inside-a-function-we-use-return-without-any-value
In Python, what does return None mean if inside a function we use return without any value? - Quora
Answer (1 of 4): You’re correct; just a simple [code ]return[/code] statement without a value will return [code ]None[/code] implicitly. The reason why this happens is because Python has no concept of void.
🌐
Finxter
blog.finxter.com › python-function-return-none-without-return-statement
Python Function Return None Without Return Statement – Be on the Right Side of Change
There are three cases of what a function can return: Case 1: The function has a return statement that returns an explicit value. Case 2: The function has a return statement that returns explicitly nothing. It returns None. Case 3: The function does not have a return statement.
🌐
Python.org
discuss.python.org › python help
Why does the my code return none!? I’m a noob so I don’t know whether the question is overtly stupid or what😃 - Python Help - Discussions on Python.org
July 25, 2021 - This returns none. Ideal behind program is to convert Celsius to Fahrenheit using Fahrenheit = (9/5) * celsius + 32 But when I write return (9/5) * c + 32 it gives the desired result Just curious on the difference b…
🌐
Codecademy
codecademy.com › forum_questions › 54f64ad795e3788c240004cc
17/19 code looks OK but return returns "None". | Codecademy
if your code indeed looks the way it does in your post, then it is possible that you have another version of your function which returns None, which is still in memory because this one didn’t overwrite the old version as this one has incorrect indentation.
🌐
AskPython
askpython.com › home › python return statement
Python return Statement - AskPython
May 11, 2023 - In Python, every function returns something. If there are no return statements, then it returns None.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-none-printed
Why does my function print None in Python [Solved] | bobbyhadz
Functions often print `None` when we pass the result of calling a function that doesn't return anything to the `print()` function.
🌐
Real Python
realpython.com › lessons › returning-none-explicitly
Returning None Explicitly (Video) – Real Python
As you’ve seen, Python will return a value of None in several situations, but there might be occasions to actually write out a return None statement. 00:19 There are basically three ways to cause a value of None to be returned from a function: if the function doesn’t have a return statement at all, if you have a return statement with no return value, or you can explicitly return None.
Published   August 10, 2021
🌐
Astral
docs.astral.sh › ruff › rules › unnecessary-return-none
unnecessary-return-none (RET501) | Ruff
Python implicitly assumes return None if an explicit return value is omitted. Therefore, explicitly returning None is redundant and should be avoided when it is the only possible return value across all code paths in a given function.
🌐
Codecademy
codecademy.com › forum_questions › 53e4fb41548c350a760021ce
Why does the return function in python always return none no matter what I have it return? | Codecademy
In this case you’ve made some functions but are you calling them ? and the answer is No. I read in another post in this forum that Python uses None to represent nothingness and I would like to think of this as a case where the program returns nothing and hence the None.
🌐
Medium
medium.com › @battesti › dont-be-afraid-of-none-in-python-it-s-the-right-way-8f950a310599
Don’t be afraid of None in Python. It’s the right way ! | by Marcu-Andria Battesti | Medium
February 11, 2025 - A function should return None when there’s no valid result to return. ... def find_item(item_list, target): for item in item_list: if item == target: return item return None # Indicates the item was not found · This makes it clear that there’s no valid result rather than returning a misleading default value. Since None is a singleton in Python...
🌐
Quora
code.quora.com › When-do-you-return-a-value-or-none-in-Python
When do you return a value or none in Python? - Code - Quora
Answer: None is itself a value in Python. It is a special value that can’t be treated as a number, can’t be treated as a string. You can compare a value to None, you can pass the value as a parameter to a called function, you can return the value to your caller.