table of Contents
Chapter VII, on the basis of the function return value 04
First, what is the return value
After some internal code function column logic processing result obtained.
def func():
name = 'nick'
return name
name = func()
print(name)
nick
Second, why have a return value
If you need to get the result of the processing functions for further processing in the program, you will need to function must have a return value
Note :
return is a function of the end of the mark
return return value can return any data type
Returns the number of return value is not restricted, separated by commas
0: Return none
A: The return value is itself
A plurality of: The return value is a tuple
\# 为什么要有返回值
def max_self(salary_x, salary_y):
if salary_x > salary_y:
return salary_x
else:
return salary_y
max_salary = max_self(20000, 30000)
print(max_salary*12)
# 函数返回多个值
def func():
name = 'nick'
age = 19
hobby_list = ['read', 'run']
return name, age, hobby_list
name, age, hobby_list = func()
print(f"name,age,hobby_list: {name,age,hobby_list}")
name,age,hobby_list: ('nick', 19, ['read', 'run'])