Skip to content

Return -1 Python

  • by

It is very simple to Return -1 in Python. Just pass the -1 into a Python function return statement. Python will stop the execution of the current function if the return statement is reached.

def fun():
     return -1

Return -1 Python

Simple example code.

def foo():
    return -1


x = -1


def goo():
    if x > -2:
        return x


# Now try the following
print(foo())
print(goo())

Output:

Return -1 Python

Do 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 *