列表推导式: #列表推导式: egg_list = [] for i in range(10): egg_list.append('鸡蛋%s'%i) print(egg_list) egon egg_list=['鸡蛋%s'%i for i in range(10)] #列表推导式 print(egg_list) # print([i*i for i in range(10)]) 生成器表达式: #生成器表达式 g = (i for i in range(10)) print(g) for i…
生成器表达式: #列表推导式 # y = [1,2,3,4,5,6,7,8] # x = [1,4,9,16,25,36,49,64] # x = [] # for i in y: # x.append(i*i) # print(x) # x = [i*i for i in y] # print(x) #range(100) # x2 = [i/2 for i in range(100)] # print(x2) #生成器表达式 # x = [i*i for i in y] # print(x)…