Good luck!
- Here are some of the built-in functions of the implementation principle (no reference source), can only be results-oriented to write their own, heart want to learn, code this thing must be manual to knock, big God do not spray
- 1. Len () returns the length, so how is it implemented?
-
-
-
-
-
- 2, Max (), min () Minimum Value code implementation principle * *
-
-
- First of all, personal feeling string is no way to compare and add , then in the string has a number of letters can still be Max (), Min () min () comparison, the string is full of numbers, we direct int cast comparison , If there is a letter special symbol will be int failure, this time will convert the letter ASCII code value to compare operations
Verify your views as follows:
-
-
-
* implementation process:tule = [3,4,2,0,7,5]max(tule)max = numbers[0] for each in numbers: if each > max: max = each return max
3. SUM () implementation process
-
-
- Sum sum operation, List of attempted support (inline list not possible), dictionary tuple, etc., type of operation such as Int,float
-
-
- Implementation principle:
-
-
-
Sorted (), reversed () implementation process
Enumerate () Implementation process
Zip () implementation process
print () implementation process
There is a free reference, I would like to use bubble sorting method to achieve sorting, floor update
function learning, in fact, functions and processes are usually learning together, the function gives me the feeling is very flexible, but also can put a lot of code package packaging, parameters for the sake of my arbitrary, can be called at any time. With regard to global variables, local variables are internally modified, including inline functions, closures (closure), and variables to fix the
Code:
def Myfunction: print(‘函数输出‘) print(‘12345678‘)
Call: Myfunction ()
Custom functions:
def add(num1,num2): result = num1+num2 print(result)
This time num1,num2 is the parameter we need to pass in.
Formal parameters (Paraneter) actual parameters (Argument)
Simply introduce the function document, since the function document must be different from the comment!
Key words:
! ‘‘ #
These are available through
1, def Myfunction. Doc
2. Help (Myfunction)
Can be seen in the function document, more standardized and neat way to show you
We can also define the default parameters as follows code
def Myfunction(a=‘你好‘,b=‘小明‘) print(a+b) print (b+a)
Although the alphabetical order changes, the output variable will change in order.
* parameter bands represent variable parameters
When modifying a global or local variable, Python has a mechanism to mask (shadowing)
When our code is running, we try to modify the global variables to create a new local variable to replace the readability of the program, and the cost of code maintenance will increase. Then we need to take the keyword to modify the variable in the process of running the code!
nonlocal (local) global (internal) * *
We can get through it. Global variables are stored in the array because the variable does not exist in the stack memory
The story of Python _two