我有如下列表。
test = ['firstvalue', 'thirdvalue']
我想在列表中插入一些值。索引1处的第二值和索引3处的第四值
所以输出列表看起来像下面的
test = ['firstvalue', 'secondvalue', 'thirdvalue', 'fourthvalue']
我尝试了以下方法,但对我来说不起作用
print test.insert(1, "secondvalue")
有其他方法吗?
insert函数不返回值,而是修改上面使用的数组
test = ['firstvalue', 'thirdvalue']
test.insert(1, "secondvalue")
print test