Skip to content

Return 0 in Python | Example code

  • by

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 different:-

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.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

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading