获得了一些示例代码:
var = [("f1","f2","f3"),("b1","b2","b3")]
print var
var[0][0] = var[0][0][1 : len(var[0][0])]
print var
如果我想替换" f1"和" 1",我该怎么做?提前谢谢!
答案 0 :(得分:3)
由于元组是不可变的,你必须为列表的整个第一个元素分配一个新的元组。
你会这样做:
var[0] = (var[0][0][1:],)+var[0][1:]
此后,var的值将为:
[("1","f2","f3"),("b1","b2","b3")]