[Python] function Getting Started 1 day 9

1. What is the function

The concept of functions: the function or operation of the packaging
benefits function: to avoid duplicate code

2, the definition of the function

1, the definition of the function

def function name (parameter list):
  function body (return)

2, call the function

Function name (argument list)

3, the return value of the function

. 1, a return value is
2, a plurality of return value returned is a tuple (a tuple can be deconstructed, unpacked)
3, a blank back return, returns None
. 4, no return, also returns None
. 5, call process function, the return encounter, behind the return code is not executed, the termination code running
  in a function call return is similar break for loop

4, the parameter (part of) the function

001 Concept
1, Concept parameters: information during a call to a function, the function is passed to the (more of argument)
2, the concept of the parameter: when defining the function, the variable is given in the form of parameters (hereinafter - parameter)
3, argument concepts: call functions, given the specific parameter is the actual value (hereinafter - argument)
4, parameter passing concept: the procedure call function, the value assigned to the argument type participation process, called mass participation

  002 Category

1, classification arguments

1, the position parameter: according to a position parameter, parameter passing - the most common
2, Keyword parameters: according parameter name parameter passed - to open file mode = 'r' encoding = 'utf -8'
3, mixing parameters:
  rules: positional parameters must be in front, key parameters must be placed at the end (or error)

2, the classification parameter

1, the position parameters: position in the order, the arrangement parameter list - most commonly
2, default parameters: default parameters must be placed in the last (or error)
  rule: If there is no argument passed by value, then the parameter - the default parameters can take the default value, effective
  if there is the argument passed by value, then the parameter - the default parameters will be covered, does not take effect

Guess you like

Origin www.cnblogs.com/wangtp/p/11525361.html