python-Syntax Basics (9) function

Source: Internet
Author: User
Tags function definition reserved

Function: A functional, reusable statement group definition function: def < function name > (< parameter (0 or more) >): < function body > return < return value > function definition The parameter specified is a placeholder and can be omitted When defining a function, you can specify a default value for some parameters, which form an optional parameter def < function name > (< optional parameter, < optional parameter >): < function body > return < return value ># You can design a variable number of parameters when defining a function, with no certainty as to the total number of parameters def < function name > (< parameters;, *b): < function body > return < return value > function call Parameters can be passed the return reserved word by location or name: The function can have a return value, or no-return can pass 0 or any number of return value local variables: A placeholder inside the function, and after the function operation is finished, the local variable is freed- Global reserved words can be used inside a function to work with globals and can be modified-local variables are combined data types and not created inside functions, equivalent to global variable lambda functions: Used to define a simple, function that can be represented within a line < functions name > = Lambda < parameters: < expression > Equivalent def < function name > (< parameter >): < function body > return < return value >

  

python-Syntax Basics (9) function

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.