What value is returned from a function that does not have a return statement?
Improve Article Show Save Article A return statement is used to end the execution of the function call and “returns” the result (value of the expression following the return keyword) to the caller. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned. A return statement is overall used to invoke a function so that the passed statements can be executed.
Syntax: def fun(): statements . . return [expression] Example: def cube(x): r=x**3 return r Example: Python3
Output: Result of add function is 5 Result of is_true function is True Returning Multiple ValuesIn Python, we can return multiple values from a function. Following are different ways.
Example Python3
Python3
geeksforgeeks 20
Python3
['geeksforgeeks', 20]
Python3
{'x': 20, 'str': 'GeeksforGeeks'} Function returning another functionIn Python, functions are objects so, we can return a function from another function. This is possible because functions are treated as first class objects in Python. To know more about first class objects click here. In the below example, the create_adder function returns the adder function. Python3
Output: The result is 25 The result is: 100 What value is returned when function does not return any?If a function does not return any value ( also called returns void) then the return type of the function will be void.
What type of function does not contain a return statement?A function that does not return a value is called a non-value returning function (or a void function). A void function will automatically return to the caller at the end of the function. No return statement is required.
|