" " Date: September 5-September 30 Requirements: 1. Summary of the book contents, finishing in the blog Park notes upload 2. After all the exercises in the course Note: "#" After the addition of the notes (42 pages per day, you can guarantee to read this book at the end of the month) "Key Notes" "chapter Exercises"-Heading 1, level two headings- Heading 2, Notes outline title, exercise title-Bold, 16px"
Key Notes
Summary
A parameter is the way an object is sent to a function as input. Parameters (argument)
I. Pass-through parameters
Here are some brief key points when the function passes a parameter:
- The argument is passed by automatically assigning the object to the local variable name.
- The assignment of the parameter name inside the function does not affect the caller
- Changing the value of a variable object parameter of a function may have an effect on the caller
Two. Specific parameter matching model
Parameters are always passed by assignment in Python. The passed-in object is assigned a variable name on the DEF header.
- Basic knowledge
Position: Match from left to right
keyword parameter : Use the syntax of name = value
default parameter : defines a parameter value for a parameter that does not have an incoming value, using a syntax such as name = value
variable Parameters : Collect any number of parameters based on location or keyword, function can use specific parameters, they are starting with a string *, collect any number of extra parameters
variable parameter unpacking : one-to-many parameters based on location or keyword
keyword-only parameter : parameter must be passed by name
- Details
Inside Python, you use the following steps to match parameters before assigning values:
① to assign non-keyword parameters by location;
② assigns keyword parameters by matching variable names;
③ other additional non-keyword parameters are assigned to the *name tuple;
④ Other additional keyword parameters are assigned to the **name dictionary;
⑤ with default values assigned to parameters not assigned to the header
Three. Examples of arbitrary parameters
- Collect parameters
The first use: in a function definition, collect mismatched positional parameters in tuples
>>> def F (*args): print >> > F () () >>> F (1) ( 1,) >>> F (1,2,3,4) ( 1, 2, 3, 4)
- The
- * * attribute is similar, but it is valid only for the keyword parameter.
>>> def F (**args): Span style= "color: #0000ff;" >print >>> F () {} >>> F (A=1,b= py " " { " b : PY , A : 1}
- Mixed usage
Function head can be mixed with general parameters, * parameters and * * parameters to achieve a more flexible call mode
def F (a,*arg,**args): print(a,arg,args) >>> F (1,2,3,x=1 )1 (2, 3) {'x': 1}
Four. Keyword-only parameters
You can use a * character in the argument list to indicate that a function does not accept a parameter list of variable lengths, but still expects all parameters followed by * To be passed as keywords.
This chapter exercises:
1.
Answer: 1 2 5
2.
Answer: 1 2 3
3.
Answer: 1 (2,3)
4.
Answer: 1,{c:3,b:2}
5.
Answer: 1 5 6 4
The 18th chapter of the Python study manual 4th