Derivation of Formula 9;. Builder send the yield from 2019-11-22

Derivation of formula (comprehensions)

Determined by a line loop, traversing a series of data mode are derived formula 
syntax: val for val in Iterable (written in the desired value for the left side)
which is one line cycle is determined in accordance with the symbol in the derivation outer sleeve! Analyzing specifically what type of derivation derivation type three kinds:   [Val Val for in the Iterable] listing derived formula   {val for val in Iterable} derived formula set   {a: b for a, b in iterable} dictionary derivations




List comprehensions, set of derivation, Dictionary derivation of the relevant wording

(1) Normal derivations 
(2) onto the formula with a determination condition
(3) to push the multi-cycle formula
(4) with a multi-cycle condition is determined to push the formula
### (. 1) the enumerate 
the enumerate (iterable, [Start = 0])
Function: enumeration; and the index value in iterable, a pair consisting of a tuple out into the iterator
parameters:
  iterable: Iteration may data (used: iterator type data container, iterables Range)
  start: start index number can be selected (default index starts from 0)
return value: iterator
### (2) ZIP 
ZIP (iterable, ... ...)
  Function: iterable plurality of values, one by one out into mating tuple consisting iterator
  iterable: data may be iteratively (commonly: iterator, container type data, iterables range)
returns: an iterator
extra element no pairing will automatically give it;

Derivation is tuple generator (Generator)

# Generator essentially iterators allow custom logic iterator # difference between iterators and generators:     iterator itself is built into the system can not be rewritten is generated user-defined, the iteration logic can be rewritten. # generator can be created in two ways:     (1) generator expression (which is a derivation, the outside parentheses)     (2) generator function (with def defined, which contains the yield)






# Yield return is similar 
in common is: to perform this sentence will return the value out
except that: yield return each time, will remember where you left off where it occurs, the next call to the generator, will be from the location of execution to go down   and return directly to the termination function, heavy head every call. yield 6 and yield (6) 2 Zhong written more like a return can yield 6 6 recommended wording

Send to the generator yield from

### send
# next和send区别:
next 只能取值
send 不但能取值,还能发送值
# send注意点:
第一个 send 不能给 yield 传值 默认只能写None
最后一个yield 接受不到send的发送值

### yield from : 将一个可迭代对象变成一个迭代器返回

Guess you like

Origin www.cnblogs.com/Liam12138/p/11840727.html