Skip to content

Python returns null function | Example code

  • by

If you want to return a null function in Python then use the None keyword in the returns statement.

Example Python return null (None).

def NoOne(x):
    return None

print(NoOne("Function Called"))


Python returns null function

Note: There is no such term as “return null” 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

To literally return ‘nothing’ use pass, which basically returns the value None if put in a function(Functions must return a value, so why not ‘nothing’). You can do this explicitly and return None yourself though.

if x>1:


if x>1:
    return None

It’s worth noting that None is not the same as an empty string (''), an empty list ([]), or a zero value (0). These are all valid values in Python that represent something specific. None is used specifically to represent a missing or undefined value.

Comment if you have any doubts or suggestions on this Python return topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *