L3. II. Return

Source: Internet
Author: User

# Function return value

Def get_max (A, B, C ):

Max_num =

If B> max_num:

Max_num = B

If C> max_num:

Max_num = C

Returm max_num

Max_number = get_max (1, 5, 3)

Print ('maxim', max_number)

Print (get_max (-2, 5, 40 ))

Get_max ()

# Function return value:

The parameter enters the function. After some business logic processing, the processed result is returned.

# The return value starts with return. It can return numbers, strings, and boolean values.

# Generally, the return value of a function is clearly defined. The calculation logic should be separated from the business logic.

# It is recommended that clear values be returned. If a function with a return value is disabled, none is returned by default.

# Easy to error: the function does not contain print (). After the function is called, the terminal cannot see the result because the terminal accepts and prints the return value of the function.

 

#2. functions that do not need to return values, but encapsulation of some functions

 

Def maday ():

Print ('upgrade ')

Print ('eat breakfast ')

Print ('workday ')

Print ('sleep ')

Print ('doubean ')

 

#3. functions that return multiple values

Def get_max_min (A, B, C ):

Max_num =
Max_min =

If B> max_num:
Max_num = B
If C> max_num:
Max_num = C

If B <max_min:
Max_min = B
If C <max_min:
Max_min = C

Return max_num, max_min

Num1, num2 = get_max_min (1, 5, 3)
Print ('maximum {}, minimum '. Format (num1, num2 ))

# A function can have multiple return values separated by commas (,) during return.
# Destructor assignment and unpackage assignment: the number of values returned by the function is accepted by the number of variables in the same order.

 

L3. II. Return

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.