如何更改列表中的某个字符?

时间:2017-06-21 12:20:11

标签: python python-3.x

我想更改/覆盖我的字符列表中的某个字符。所以,如果我有一个包含大量字符的列表,我想用其他字符替换第一个someList[0]。我试过someList[0] == "g",但它没有用。

1 个答案:

答案 0 :(得分:5)

=,而非==,因为=是赋值运算符,==是等号运算符

someList = ["a", "b", "c", "d", "e"]
someList[0] = "g"
print(someList)

输出:

['g', 'b', 'c', 'd', 'e']