我有一段python代码
def getAvailableLetters(lettersGuessed):
str='abcdefghijklmnopqrstuvwxyz'
for i in lettersGuessed:
if i in str:
str.replace(i,'')
return str
getAvailableLetters(['a','v','k','k','l','i','o','0'])
问题是str.replace(i,'')
不起作用。请帮助我理解为什么?
答案 0 :(得分:3)
str.replace(i,'')
不会更改实际的字符串,您需要
str = str.replace(i,'')