There is no such thing as "returning nothing" in Python. Every function returns some value (unless it raises an exception). If no explicit return statement is used, Python treats it as returning None.

So, you need to think about what is most appropriate for your function. Either you should return None (or some other sentinel value) and add appropriate logic to your calling code to detect this, or you should raise an exception (which the calling code can catch, if it wants to).

Answer from Blckknght on Stack Overflow
🌐
Finxter
blog.finxter.com › home › learn python blog › python return nothing/null/none/nan from function
Python Return Nothing/Null/None/NaN From Function - Be on the Right Side of Change
August 1, 2023 - To return an empty value or “nothing” from a Python function, you can use the return statement followed by the keyword None. For example:
🌐
Reddit
reddit.com › r/learnpython › how to have python return nothing instead of none?
r/learnpython on Reddit: How to have Python return nothing instead of None?
February 3, 2022 -

Python and I are NOT getting along today.

I have the script below, which takes arguments like username and fromdate and passes it into the appropriate place in the URL (the link variable). Now, if the user just inputs username and doesn't input fromdate, Python will return None instead of nothing. Why do you do this, Python!? I never asked you to!

How can I avoid this monstrosity?

Command

main.py  -u jacksfilms

Script

import requests, re, argparse

parser = argparse.ArgumentParser()
parser.add_argument('-u','--username', required=False)
parser.add_argument('-from','--fromdate', required=False)
parser.add_argument('-to','--todate', required=False)
args = vars(parser.parse_args())
username = args['username']
fromdate = args['fromdate']
todate = args['todate']

link = "https://web.archive.org/cdx/search/cdx?url=twitter.com/{}/status&matchType=prefix&from={}&to={}".format(username,fromdate,todate)
data = []

c = requests.get(link).text
urls = re.findall(r'https?://[^\s<>"]+[|www\.^\s<>"]+', c)

for i, url in enumerate (urls):
    data.append(f"{i}: {url}\n")
    
print(data)
🌐
Julianhysi
julianhysi.com › post › 4
Julian's Blog - Bare return vs return None vs no return
If the function should return a value, the return statement in Python is no different than the languages I mentioned earlier: But what if the function isn't supposed to return anything ? A great example are methods which act on the object at hand, such as my_list.sort().
🌐
Boot.dev
boot.dev › lessons › 589229bc-0245-4aca-ac0e-aa07a904b283
Learn to Code in Python: None Return | Boot.dev
For example, maybe it's a function that prints some text to the console, but doesn't explicitly return a value. The following code snippets all return the same value, None: def my_func(): print("I do nothing") return None ·
🌐
Designcise
designcise.com › web › tutorial › how-to-return-nothing-or-null-from-a-python-function
How to Return Nothing/Null From a Python Function? - Designcise
November 13, 2022 - You can return None explicitly in a function like so: def foo(x): if x == 0: return None return 'foo' print(foo(0)) # None print(foo(1)) # 'foo' Returning an empty return in a function is the same as returning None explicitly:
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      
🌐
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.
Find elsewhere
🌐
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
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. The function in that case implicitly returns None. ... Feel free to check out our Python cheat sheets to learn about all the Python basics and keywords and tricks:
🌐
EyeHunts
tutorial.eyehunts.com › home › return nothing python | example code
Return nothing Python | Example code - EyeHunts
January 26, 2022 - In most cases, you don’t need to explicitly return None. Python will do it for you. def foobar(check): if check: return "Hello" print(foobar(False)) ... Do comment if you have any doubts and suggestions on this Python basic tutorial.
🌐
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.
🌐
Python Morsels
pythonmorsels.com › none
None in Python - Python Morsels
January 22, 2024 - Where does None come up? Well, conventionally None is used for saying "there's nothing here". The dictionary get method is a good example of where None appears. The get method can look up a value for a key or return a default value when that key is missing:
🌐
Real Python
realpython.com › lessons › returning-none-explicitly
Returning None Explicitly (Video) – Real Python
Now that you know the syntax of writing return statements in Python, let’s take a look at some best practices when using it. First, we’ll look at returning None explicitly. As you’ve seen, Python will return a value of None in several situations…
Published   August 10, 2021
🌐
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 between print ((9/5) * c + 32) and return
🌐
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() ->...
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-return-null-in-python
How to return null in Python ? - GeeksforGeeks
July 23, 2025 - def my_function(): return None # Call the function and store #the returned value in the variable 'result' result = my_function() print(result) ... In Python, None is used to represent a null value or the absence of a result.
🌐
EyeHunts
tutorial.eyehunts.com › home › python function return nothing
Python function return nothing
June 28, 2024 - def example_function_1(): pass # No return statement def example_function_2(): return None # Explicitly returns None def example_function_3(condition): if condition: return "Condition met" # No return statement if condition is False def example_function_4(value): if value > 10: return "Greater than 10" # No return statement if value is 10 or less result1 = example_function_1() # result1 will be None result2 = example_function_2() # result2 will be None result3 = example_function_3(False) # result3 will be None result4 = example_function_4(5) # result4 will be None print(result1) # Output: None print(result2) # Output: None print(result3) # Output: None print(result4) # Output: None
🌐
Quora
quora.com › Why-does-the-programming-language-Python-return-none-instead-of-nothing
Why does the programming language Python return none instead of nothing? - Quora
Answer (1 of 3): If a function fails to return you would get Nothing back - if it returns but doesn’t have any value(s) to return then you get back [code ]None [/code]- not that python functions can return more than one thing at a time, may return mixed types and are not required to return ...
🌐
Code with C
codewithc.com › code with c › python tutorials › where python returns nothing: understanding python’s none
Where Python Returns Nothing: Understanding Python's None - Code With C
December 26, 2023 - Here, we put risky_division to test with two real-world scenarios: one, a hopeful (and successful) divide operation, and two, a risky dive into the void of dividing by zero. The outcome of each is handed over to print_result, which does its thing, and voilà! We have a fine example of handling and communicating the case where Python returns None.