Example Analysis of return Statement usage in Python and python instance analysis
This example describes the return statement usage in Python. Share it with you for your reference. The details are as follows:
Return Statement:
Return statements are used to jump out of a function when a function is returned. We can also return a value from the function.
Use literal statements
#! /Usr/bin/python # Filename: func_return.pydef maximum (x, y): if x> y: return x else: return yprint maximum (2, 3)
Output
$ Python func_return.py3
Working principle:
The maximum value in the return parameter of the maximum function. Here it is the number provided to the function. It uses a simple if... else statement to find a large value and then return that value.
Note that a return statement without a return value is equivalent to return None. None is a special type in Python that indicates nothing. For example, if the value of a variable is None, it indicates that it has no value.
Unless you provide your own return statement, each function contains a return None statement at the end. By running print someFunction (), you can understand this. The someFunction does not use the return statement, as shown below:
Def someFunction (): pass
The pass statement indicates an empty statement block in Python.
I hope this article will help you with Python programming.