2024-04-20 13:28:27 发布
网友
如何更容易地或一行地编写这些代码段
dist=[] for k in range(5): dist.append(k) dist[0]="Apple" print(dist)
>>> dist = ['Apple', *range(1, 5)] >>> dist ['Apple', 1, 2, 3, 4]
Python2.7(也适用于Python3+):
>>> dist = ['Apple'] + [i for i in range(1,5)] >>> dist ['Apple', 1, 2, 3, 4]
Python2.7(也适用于Python3+):
相关问题 更多 >
编程相关推荐