Python - Function def Statements

Introduction

The def statement creates a function object and assigns it to a name.

Its general format is as follows:

def name(arg1, arg2,... argN): 
    statements 

Function bodies often contain a return statement:

def name(arg1, arg2,... argN): 
    ... 
    return value 

Python return statement can show up anywhere in a function body.

When return statement is reached, it ends the function call and sends a result back to the caller.

The return statement consists of an optional object value expression that gives the function's result.

If the value is omitted, return sends back a None.

The return statement itself is optional too.

If it's not present, the function exits when the control flow falls off the end of the function body.

Technically, a function without a return statement also returns the None object automatically.

Related Topics