Return 0 in Python | Example code

The return keyword is what informs the function if it should return a value or not. If no value is given to the return or no variable is assigned to be returned, then the return value is None

Function Return 0 in Python if assign a value is 0 and the function will end when the return keyword and value is reached.

Example Function Return 0 in Python

0 is not equal to None. However, in boolean context, they are diffrent:-

def do_1():
    return 0


def do_2():
    return


print(do_1(), do_1() == 0)
print(do_2(), do_2() == 0)

Output:

Return 0 in Python function

A python function would return 0 either because of some computation:

def add_2_numbers(a,b):
    return a + b      # 1 -1 would return 0

Why would a function end with “return 0” instead of “return” in python?

In Python, every function returns a return value, either implicitly or explicitly.

Do comment if you have any doubts and suggestions on this Python return tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.