List Builder is a very simple but very powerful built-in python.
Generate a list [1,2,3,4] can use list (range (1,5))
Application of List Builder
If the above formula is judged, you can filter out the desired result, such as just the square of the even number
Using multi-layer loops
Generator
The essential difference between a generator and a list generator is that one has generated data, and when used, it generates a memory overflow if the data is too large and generates data only when the generator is a loop.
The difference between a generator and a list generator is that one is [], one is ()
Generator Write
g= (x x ()) (g)
The way to print generator is next (g) and for loop
Print the Fibonacci sequence in the form of a function
(max): Nab=n < max: (b) ab=ba+b N=n+fib ()
The above function and generator are only a step away, to turn the FIB function into generator, simply change print (b) to yield to
(max): Nab=n < max:b ab=ba+b N=n+fib ()
To print the generator method for FIB
I fib (): (i)
If you call generator with a For loop, you want to get the return value, you need to capture the stopiteration error, and the return value is contained in the value of stopiteration:
G=FIB (6)
(max): Nab=n < max:b ab=ba+b N=n+g=fib ():: x= (g) (x) E: (E.value)
Python List Builder and generator