Detailed explanation of supplementary functions

Detailed explanation of supplementary functions

First, the definition of the function

  definition

import re

def myadd(num1,num2): #Function      header " 
    "" #Function                    interface
    Calculate the sum of two numbers
    :param num1: the first number
    :param num2: the second number
    :return: and
    """ 
    res = num1 + num2     #function body return res           #return statement
    

  transfer

#function name plus parameters

  parameters, syntax

#Formal parameters: 
#Formal parameters, parameters written when defining a function #Category 
: Required parameters: must be passed in actual parameters 
#Default          parameters: When no actual parameters are passed, there are default values, and passing actual parameters will overwrite; when defining It should be written after the required parameters (this is the syntax) 
#Ordinary          dynamic parameters: *args * is the keyword, args is the parameter name, usually written as args; when calling the function, all incoming redundant positional parameters will be args receives and forms a tuple 
#Keyword          dynamic parameters: **kwargs ** is a keyword, kwargs is a parameter; all redundant keyword arguments passed in by cuan will be received by kwargs to form a dictionary
    


#Actual parameters: #The actual parameters passed in by the calling function 
, referred to as actual parameters 
# Classified according to the way of passing parameters: Positional parameters: The actual parameters written directly in the parentheses, which correspond to the formal parameters one-to-one according to the order of positions   
#                              Keyword parameter: The corresponding relationship between the specified formal parameter and the actual parameter displayed by the key-value pair when passing the parameter

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324522900&siteId=291194637