python 中列表推導式的練習
阿新 • • 發佈:2018-12-20
print("~"*100) # print("python中的列表推導式的練習") # # list = [ i for i in range(1,10)] # print(list) # list = [i*i for i in range(1,10)] # print(list) print("求乘積: "*10) list = [i*i for i in range(1,10)] print(list) print("求加一: "*10) list = [i+1 for i in range(1,10)] print(list) print("求偶數: "*10) list = [i for i in range(1,10) if i%2 == 0 and i > 4] print(list) print("求乘積: "*10) list = [{i:j} for i in range(1,10) for j in range(1,10)] print(list) print("求乘積: "*10) list = [{i,j,k} for i in range(1,10) for j in range(1,10) for k in range(1,10)] print(list) for i in range(1,10): for j in range(1,10): for k in range(1,10): print(i,j,k)