1. Function: Encapsulate a function
|def My_len (formal parameter): DEF declaration defines a function My_len function name naming rules same variable
|
| ······
| ······ -> function body, write code to achieve the desired function
| ······ Using formal parameters in the body of the function to make internal modifications to external mutable data type variables
| ······
| return x, which is returned when you encounter return, does not perform the following
| ······
|
|my_len (argument)-here executes the function, that is, the calling function needs to declare the definition before calling the format: function name + ()
To pass the parameter:
My_print (' 123 ', ' abc ', ' Satan ') positional arguments, i.e., based on (concrete argument value) one by one corresponding to the parameters passed to the parameter
My_print (b= ' 123 ', c= ' abc ', A= ' Satan ') key-pass argument, that is, the argument is passed (parameter name)
My_print (' 123 ', b= ' abc ', c= ' Satan ') mixed, that is, (the key argument) must be all at the back of (the positional argument).
Default parameters:
def my_print (a,b,c=none,d={}) the formal parameters with default values must all be behind formal parameters with no default values.
On the inside of a function, the difference between a reference to an external (variable of variable data type list,dict) and a reference to an external (variable of immutable data type, such as INT,STR):
Reference: https://www.cnblogs.com/kayb/p/7194006.html
(You cannot change the direction of a global variable.) )
Again, if I is {}: This comparison is the memory address that is compared to the small data pool. Variable data types such as dictionaries, lists, and no small data pools.
A preliminary knowledge of Python Day9 note function