如何在字符串中添加一些元素?我写了这段代码,但它给了我这个错误:
“frase2[i] += frase[i]
IndexError:字符串索引超出范围“
我的代码是:
def copia(frase):
i = 0
while i < len(frase):
frase2 = ""
if (frase[i] >= 'a' and frase[i] <='z') or (frase[i] >= 'A' and frase[i] <= 'Z'):
frase2[i] += frase[i]
else:
frase2[i] += " "
i += 1
return frase2
frase = getString("Inserisci frase: ")
print(copia(frase))
我怎样才能解决这个问题?
翻翻过去那场雪
繁花如伊
largeQ
相关分类