Python function definition and use + return value simple solution

Source: Internet
Author: User

A function is equivalent to a function block, and when it is to be used, it can be called directly, avoiding the base code.

function definition and use:

1 #function2 defMail ():#Defining Functions3n = 123#function Body4n + = 15     Print(n)6Mail ()#parentheses represent the execution function7f = Mail#function name, same as assignment result8 f ()9 Ten #Execution Result: One124 A124
    • def: A keyword that represents a function (parser resolves to def, recognizes as defined function, does not execute by default)
    • Function name: the names of functions, which are called later by function name
    • Function Body: A series of logical calculations in a function, such as sending a message, calculating the maximum number in [11,22,38,888,2], etc...
    • Parameters: Providing data for the function body
    • Return value: When the function is finished, you can return the data to the caller, and if you do not set the return value, the function returns the value, but none.

function return value: Can be used to determine whether the function is successfully executed

1 #function return value2 defMail ():#Defining Functions3n = 123#function Body4n + = 15     Print(n)6     return123#If the function executes successfully, it returns 123, and if the return value is not set, the function returns the value, but none. 7ret = mail ()#parentheses represent the execution function8 Print(ret)9 Ten #Execution Result: One124 A123
1 defShow ():2     Print("a")3     if1 = = 1:#when 1==2, it will output B4         return[11,22]#when the function encounters a return, it returns, no longer executes the following5     Print("b")6 Show ()7 8 #Execution Result:9A

Python function definition and use + return value simple solution

Related Article

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.