Article we'll look at the return statement in Python. First we need to understand the use
of the return statement, and then we know what the return statement is
used for , and what kind of knowledge is
behind the return statement . Without saying much, let's get to the point and get to know the return statement in Python.
Return statement:return statement [expression] exits the function, optionally returning an expression to the caller. A return statement without a parameter value returns none. Return is simply the return of the value in the function to the place where the statement was called, but just a return, usage is too much too flexible in the main function, can be used as a function of the end of the flag, in the calling function can use to return the required value, can also be used to flag whether the program run satisfies a certain condition.
Let's give an example as follows:
#!/usr/bin/python#-*-coding:utf-8-*-# writable function Description def sum (arg1, arg2): # Returns the sum of 2 parameters. " Total = arg1 + arg2 print "in function:" ; # Call the sum function total = SUM (10, 20);
The above example outputs the results as follows:
Inside function: 30
The return statement is a value returned by a function in the Python language, and each function should have a return value, where the return value can be a numeric value, a string, a Boolean value, or a list. The Python function returns the value return, the function must have return return value is the complete function, if you do not define the Python function return value, then get a result is a None object, and none means that there is no value.