python generation expression

Learn a code amount can save a lot, but also facilitate the use of 
the following are a few examples:

# list creating the expression
A = [I for I in Range (. 5)% 2 == 0 I IF]
Print (A)
# dictionary generation expression
I = {B: I% 2 == 0 for I in Range (10)}
Print (B)
# tuples for the generation of an expression, which is not called tuples generated expression, called generator expression
c = (c Range in C for (10))
Print (C) is a C # generator
Print (SUM (C)) # expressions can be generated as a function of the parameter
print (sum (range (5) ))

Guess you like

Origin www.cnblogs.com/sylarwang/p/12068339.html