Python Basic-day9-function

Source: Internet
Author: User

  • Programming method
    • 1, process-oriented programming: According to business logic from top to bottom code to implement the function
    • 2, functional programming: to encapsulate a function code in the function, the use of the same function later, no need to write, direct function calls can
    • 3. Object-oriented programming: classify and encapsulate functions to make development "faster, better and stronger"
  • function-type programming
    • function definition
      • will be able to implement some kind of function, reusable, organized code block together
    • Functions of the function
      • Enhanced reusability and readability of code
    • function syntax
      • def function name (parameter optional)
        • function body (code block)
        • Return
    • The function returns the value return
      • The result returned to the caller after the function has been executed (the caller is required to accept by defining the variable)
      • The function ends when it encounters a return, no longer executes the following code, ends the function
        • Do not write return, Python built-in rules return none by default
        • Return None, returning none
        • Return a single value that returns this single value
        • Return multiple values, including multiple values in (tuples), returned to the caller (can be directly accepted by defining the deconstruction)
    • function Parameters
      • Parameter: A variable in the position of a function declaration that declares a variable in parentheses
        • Position parameters
        • Default parameters
          • 1. The positional parameter must be declared before the default parameter can be declared
      • Argument: The value that the caller actually passes to the function when it invokes the function
        • Position parameters
        • Keyword parameters
        • Mixed parameters
          • 1, position parameters and keyword parameters mixed use
          • 2, must first write positional parameters, after the keyword parameters, or error: (syntaxerror:positional argument follows keyword argument)
    • Ternary op-expression
      • A = 1
      • b = 2
      • c = A If a > b Else B # C equals if A is greater than B, and no is equal to B

Python Basic-day9-function

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.