Discover the small usage of pycharm
This calling method is called positional arguments, and parameters are passed in in the order of calling
This is a more general demonstration of the above example
Keyword argument call method
This is called an arbitrary argument. If you use this when you don't know how many parameters the user will pass in the future when calling the function, it will be assembled into a tuple object and passed to this deformable parameter.
To call this function, you must pass in two parameters
Join us now, such a requirement is to put these two numbers in a tuple or list?
error
This time it's ok, but it's numb. It's more troublesome
If you add a * as an actual parameter and pass it to the called function, python will automatically parse the parameter from it to the function
This method is called: unseal the argument list
● The parameter of a function can have a default value, which is called a default parameter. The parameter with an * before the parameter name is called a deformable parameter, and the parameter with two ** before the parameter name is called a dictionary parameter. The deformable parameter must be after the non-default parameter, the default parameter must be after the non-default parameter and the deformable parameter, and the dictionary parameter must be placed last.
● The formal parameters in the function definition are in order. The actual parameters can be passed to the formal parameters according to the position, which is called the positional actual parameter, or the actual parameter can be passed to the formal parameter in the form of formal parameter name=actual parameter, which is called the key Word argument. The keyword arguments can be arranged in any order.
● You can pass multiple actual parameters to the deformable parameter, and these actual parameters are packed into a tuple object and passed to the deformable parameter. The function can access the actual parameters in the deformable parameter like a normal tuple object.
● It is possible to pass the dictionary parameters to the dictionary parameters in a key-value manner. These key-value arguments are packaged into a dictionary object and passed to the dictionary parameters. The function can access each key-value argument in the dictionary parameter like a normal dictionary object.
● If the actual parameters to be passed to the function are placed in a tuple or list object, they can be passed to the called function by adding * in front of the variable name that points to the object. The parameter will be unblocked and passed to the formal parameter of the called function. If the actual parameters to be passed to the function are placed in a dict object, you can pass the dictionary actual parameters to the formal parameters by adding ** in front of the variable name that points to the object.
Recommended Posts