Recently followed by the Liaoche teacher's Python tutorial is studying, summarizes the study achievement
function definition:
When no return statement is returned, the result is None
def function name (): function Body return value
Function call:
We can call a function in Python, or we can call a custom function, provided that the correct arguments are passed in
Function parameters:
The function parameter is divided into the required parameter default parameter, the variable parameter, the keyword parameter and the named keyword parameter (the order of the parameter definition is also such)
The *args is a variable parameter and is accepted as a tuple
**KW is a keyword parameter that accepts a dict
Practice:
The following function allows you to calculate the product of two numbers, modify it slightly to accept one or more numbers and calculate the product:
def product (x,*kw): s=1 for in range (len (kw)): s=s* Kw[i] Print (x*s) product (+/-)
Product (1,2,3,4,5,6)
The results of the operation are as follows:
Thinking:
I didn't know how to do it at first, it was a headache, and here's my thinking steps.
1. Temporarily consider some of the column numbers that can be entered as a variable parameter, using the traversal of a tuple to loop all the numbers out
2. Set an initial variable s and initialize s to 1, after each loop, multiply with s and give s re-assign value
3. Output results can be
Summary:
The code is still more thinking, more practice
The function of Python learning