您如何覆盖列表中的项目?

时间:2019-10-30 13:24:14

标签: python-3.x

您如何覆盖列表中的项目?

我尝试过,但是没有用。

numbs = [5, 10, 15, 20, 25]
i = 0
for numb in numbs:
    numbs[i] = (numb+5)
    i+=i+1

2 个答案:

答案 0 :(得分:1)

尝试一下:

numbs = [numb+5 for numb in numbs]

答案 1 :(得分:0)

尝试一下:

numbs = [5, 10, 15, 20, 25]
i = 0
for numb in numbs:
    numbs[i] += 5
    i += 1
print(numbs)

我从中得到的输出是:[10,15,20,25,30]