Help for the Fun_name function can be viewed in the interactive command line using Fun_name
Data type conversion int () float (); STR (); BOOL ();
Define a function to use Def for example: Def nes_def (x): Then write code in the indentation using return return function value if no return returns none
When the function has more than one parameter, the parameter with large change is put in front, and the parameters with small change are put back. Parameters with small variations can be used as default parameters.
When calling a function, you need to precede the value with a parameter name, such as New_add (Name= ' xiaoming '), when the parameter value is not filled in order;
The default parameter must point to an immutable object. such as name=none or fixed values;
The function uses the variable parameter Def power (*number); You need to add a "*" to the argument before the parameter, and this result returns a type of tuple
When a user needs to call a list or a tuple as a function parameter, you can pass all the elements in this list as mutable arguments to the function by writing the * number in front of the list or tuple in the argument directly when the function is called.
def power (*number): xxx;
N_list = [1,2,3,4];
Power (*n_list);
The keyword parameter uses "**name" to declare a keyword parameter to generate a dict in the function to accept custom or non-passing values
def power (num,int,**outher): xxx; Power (1,4,city= ' Guilin ', age=15,sex=1);
Its use of the keyword parameter value requires the use of dict in the format name= ' xiaoming '
You can also directly override the function in the dict directly within the function of the dict also only need to use the "* *" number can be
new_dict={' city ': ' Guilin ', ' age ': +, ' sex ': 1}; Power (1,4,**new_dict);
Restrict named keyword parameter declaration method def power (num,int,*,city,sex): xxx;
Just set "*" to a parameter, "*" after the parameter name, is named keyword parameter
At this point, the function within the dict only accepts "*" after the parameter value of the specified parameter name
If there is already a mutable parameter in the function definition, then the named keyword argument will no longer need a special delimiter "*"
def person (name, age, *args, City, job): XXX;
The named keyword parameter must pass in the parameter name, and the call will error if the parameter name is not passed in. (You can also set default parameter values)
Recursive functions that call themselves inside a function are recursive functions
Tail recursive optimization: so that the recursive itself, regardless of the number of calls, only occupy a stack frame, there is no stack overflow situation.
Python Study the next day