List-generated lists comprehensions
[element to be generated x for loop x if judgment]
[element to be generated x, Y for loop × for loop y]
[key+ ' = ' + ' value ' for Key,value in Dict.items ()]
Isinstance (X,type); Judging variable types
Pass statement to occupy a bit and no egg to use
The generator generator one side of the loop while the mechanism of the computation generator saved is the algorithm
L = [x for x in range (0,11) if x%2 = = 0]
Change the list-generated "[]" to "()" that is the generator
L = (x for x in range (0,11) if x%2 ==0);
Generator view data needs to use next (x); You can get one data per execution or use a for iteration
If a function definition contains the yield keyword, then the function is no longer a normal function, but a generator.
function differs from generator function
The function is executed sequentially to the last line or returned in the event of a return
The generator function executes at each call to next () when it encounters a yield statement that returns execution from the yield statement that was last returned
An iterator iterator an object that can be called by the next () function and continually returns the next value is called an iterator.
The ITER () function turns list,dict,str into iterator objects
All objects that can be used for a for loop are iterable types;
All objects that can be used for the next () function are iterator types, which represent a sequence of lazy computations;
Collection data types such as list, Dict, str, and so on are iterable but not iterator, but a iterator object can be obtained through the ITER () function.
Python Study the third day