task5

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Ha1Ozzz/article/details/102750548

1. Defined Functions
function definition, the def keyword, greet_user as a function name, username parameter as a function of
return [Expression] End function, selectively returns a value to the caller. Return without an expression equivalent to return None. Here Insert Picture Description
2. The real parameter participating
in the definition of the function parameter is a parameter; parameter in the function call is the argument
in python, the object type is, there is no variable type, and strings, tuples, and numbers can not be changed the object, list, dict and so it can be modified objects.

Plus an asterisk * parameter will be introduced as a tuple (tuple), and storage of all variables unnamed parameters. Plus two asterisks ** parameters will be introduced as a dictionary. When you declare a function argument asterisk * can occur alone, but the parameters asterisk * after the emergence of the individual must be passed by the keyword.
python using lambda to create an anonymous function. Just a lambda expression, function body is much simpler than def.
The filter (x, y): y is filtered off value of x does not meet the
map (x, y): the value of y by x to obtain a new value

lambda function has its own namespace, and can not be accessed outside its own parameter list or the global namespace parameters.

Although lambda function looks can only write a single line, but not equivalent to C or C ++ inline functions, which aims not take up the stack memory when calling small functions to increase operating efficiency.

Keyword arguments: the argument parameter is assigned, the program will not be in order, but by keyword parameters
default parameters: initial value for the parameter when the parameter defined such assignment will forget when calling the program automatically find the initial error does not occur, with the default value instead of the
collection parameters: You can not define a function in the end the number of parameters in parentheses before parameter when adding a function definition *, it becomes a collection parameters (variable parameter)
variables defined in a local variable called the function, the function will no longer function

Guess you like

Origin blog.csdn.net/Ha1Ozzz/article/details/102750548