Home > Backend Development > Python Tutorial > What is the return statement? What role does the return statement play?

What is the return statement? What role does the return statement play?

乌拉乌拉~
Release: 2018-08-15 13:52:01
Original
9586 people have browsed it

In this article, let’s take a look at the return statement in python. First of all, we need to understand the usage of the return statement, then know what the return statement is used for , what kind of use this statement has, and we also need to understand what return statement is followed by This kind of knowledge. Without further ado, let’s get down to business and learn about the return statement in Python.

return statement: return statement [expression] exits the function and optionally returns an expression to the caller. A return statement without parameter values ​​returns None. Return simply means returning the value in the function to the place where this statement is called, but it is just a return. The usage is too many and too flexible. In the main function, it can be used as a sign of the end of the function. It can be used in the calling function. To return the required value, it can also be used to mark whether the program meets certain conditions.

Let’s take an example as follows:

#!/usr/bin/python# -*- coding: UTF-8 -*-
 # 可写函数说明def sum( arg1, arg2 ):   # 返回2个参数的和."
   total = arg1 + arg2
   print "函数内 : ", total
   return total; 
# 调用sum函数total = sum( 10, 20 );
Copy after login

The output result of the above example is as follows:

函数内 :  30
Copy after login

The return statement is returned by the function in the Python language A value, every function should have a return value; the return value can be a numeric value, a string, a Boolean value or a list. The Python function returns the value return. There must be a return value in the function to be a complete function. If you do not define a Python function return value, then the result you get is a None object, and None means there is no value.

The above is what I want to explain today, explaining the function and usage of the return statement. Although the above knowledge points give examples, you still need to try it yourself. Just looking at the theory is like talking on paper. Hands-on practice is the best method and way to verify what you have learned. Finally, I also hope that this article can bring some help to you who are learning python

For more related knowledge, please visit the Python Tutorial column of the php Chinese website.

The above is the detailed content of What is the return statement? What role does the return statement play?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template