练习
v1 = [ i for i in 'alex' ] # ['a','l','e','x']
v2 = [i+100 for i in range(10)] # [100,101,102,103,104,105,106,107,108,109]
v3 = [99 if i>5 else 66 for i in range(10)] # [66,66,66,66,66,66,99,99,99,99]
def func():
return 100
v4 = [func for i in range(10)] # [func,func,func,func,func,func,func,func,func,func,]
v5 = [lambda : 100 for i in range(10)] # [lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100,lambda : 100]
result = v5[9]() # 100
v6 = [lambda :i for i in range(10)] # [lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,lambda :i,]
result = v6[5]() # 9
v7 = [lambda x:x*i for i in range(10)]
# 1.请问 v7 是什么?
v7 = [lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,lambda x:x*i,]
# 2.请问 v7[0](2) 的结果是什么? v7[0](2) = 18
def num():
return [lambda x:i*x for i in range(4)]
# num() -> [函数,函数,函数,函数]
print([ m(2) for m in num() ]) # [6,6,6,6]
# ##################### 筛选 #########################
v8 = [i for i in range(10) if i > 5] # [6,7,8,9]