如何将列表中的某些元素乘以0?

时间:2019-11-13 16:13:51

标签: python python-3.4

我想知道如何将列表中的某些项目乘以0以再次使列表空白。我之所以需要这样做,是因为我已经在代码中实现了圆形系统。

totalround1 = [coupleAtotal ,coupleBtotal,coupleCtotal,coupleDtotal,coupleEtotal,coupleFtotal]

totalround1.sort()
print(totalround1)
index0= totalround1[0]
index1= totalround1[1]
index2= totalround1[2]
index3= totalround1[3]
index0 * 0
index1 * 0
index2 * 0
index3 * 0
print(index0,index1,index2,index3)

它返回与以前相同的值,我想知道如何解决此问题。

1 个答案:

答案 0 :(得分:0)

您实际上并没有在代码的后半部分更改索引。您只是将它们乘以零而不存储它们。这样做:

totalround[2] = 0

代替