更改列表元素需要索引.
list_object[index] = new_value
使用enumerate,您可以迭代列表并获取索引.
enumerate
>>> x = [[1,2], [1,4]] >>> for i, element in enumerate(x): ... if element[1] == 2: ... x[i] = [5,5] ... >>> x [[5, 5], [1, 4]]