1) Condition judgment and circulation
If ....... else: .....
For xx in yy: ... while xx: ...
2) Dict and set:
Dict
{Key:val} using Key-value storage, with extremely fast lookup speed, key is immutable
Compared with list, Dict has the following characteristics: The search and insertion speed is very fast, will not increase with the increase of key, need to occupy a lot of memory, memory waste much
Set
A combination of key. ([Key,key,key]) [] does not mean a list, repeating elements are filtered
3) function
def definition
Parameters of the function:
Default parameter: A default value is given when the function is defined. Note: The default parameter must be followed, and the default parameter must point to the immutable object, otherwise you will change the value of the default parameter as soon as you call it
Variable parameter: *numbers use numbers when calling parameters below. But inside the function, this numbers is a tuple. Not a number
Keyword parameters: **kw kw accepts a dict, which is the legendary dictionary. Owning key and value
def person (name,age,**kw): print ' name: ' Name, ' Age: ' Age, ' other: ' kw
Parameter combination: Order is important required parameter, default parameter, variable parameter, keyword parameter
Recursive functions:
There is an if to terminate the recursion. Otherwise, it keeps calling itself in else.
4) Advanced Features
Slices: List and tuple a[1:3] intercept starting from 1 to 3 end not including 3. equals = = >[1,3)
Iteration: For Loop
For key in Value:print key
List Builder: [] expression or an expression of an argument in an equation, or a source.
Import OS [D for D in Os.listdir ('. ')]
Generator function:
Use ()
In the process of the cycle of continuous calculation of subsequent elements, saving space
If a function definition contains the yield keyword, then the function is no longer a normal function, but a generator
The generator is not the same as the function in which the function is executed sequentially. Encountered return returned. Next time in this way. The generator is not the same, and each call to Next () is performed. When yield is met, it is returned, and the next time it is executed again from this yield place.
This article from "ehealth" blog, declined reprint!
Python Basic Learning---2