Thursday, March 28, 2024
HomePythonPython Perform Return None With out Return Assertion – Finxter

Python Perform Return None With out Return Assertion – Finxter


The Python return key phrase means that you can outline the return worth of a operate (e.g., return X). In case you don’t explicitly set a return worth otherwise you omit the return assertion, Python will implicitly return the next default worth: None.

There are three circumstances of what a operate can return:

  • Case 1: The operate has a return assertion that returns an express worth.
  • Case 2: The operate has a return assertion that returns explicitly nothing. It returns None.
  • Case 3: The operate doesn’t have a return assertion. The operate in that case implicitly returns None.

Let’s have an instance of all three circumstances subsequent!

Case 1: The operate has a return assertion that returns an express worth.

def f1():
    return 42

print(f1())
# 42

Case 2: The operate has a return assertion that returns explicitly nothing. It returns None.

def f2():
    return

print(f2())
# None

Case 3: The operate doesn’t have a return assertion. The operate in that case implicitly returns None.

def f3():
    move

print(f3())
# None

Be happy to take a look at our Python cheat sheets to find out about all of the Python fundamentals and key phrases and methods:


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments