Python function programming

Source: Internet
Author: User

I. Definition and invocation of Python functions

the definition of a function : (function) code block.

is to integrate the code we want to execute into a code block that can be called.

Functions are blocks of code that can be called repeatedly, with several advantages:

    • Reduce Code Redundancy
    • Code Structure Clear
    • Helps keep your code consistent

Division of Functions

    • Divide by parameter type
      • Positional parameters: is the way that we pass the arguments in the order in which they are passed, as defined by the parameters

      • Keyword parameter: It is when we pass the parameter, we ignore the order of the form parameter equal to the argument, and then we pass the parameter.

      • Default parameter: When defining a parameter, a default value is given to the formal parameters. When a function is called, the default value is automatically applied if no parameter is passed to the default value. "NOTE: The default parameter must be written after the normal parameter"

    • Divide by return value "difference is whether there is a return value"
      • return type function "have"
      • Computed type function "None"

Ii. Anonymous functions and maps

    • Lambda anonymous functions are one of the functions in Python.

The difference: Def defines a function as a statement block, whereas a lambda function is an expression.

The DEF function has a function name, and the lambda function has no

The lambda function body can only be an expression, and the result is automatically fed back

    • The map function executes in bulk: The following sequence is called sequentially as a parameter of the preceding function

Python function programming

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.