我對Python非常陌生,目前我正在開發一個用於加密和解密字符串的程序。作爲它的一部分,我需要將字符串的單個字母添加到空列表中;例如,字符串「hello」將進入一個名單列表,像這樣:Python - 列表索引超出範圍For循環
['h','e','l','l','o']
是給我這個錯誤代碼的部分可以在下面找到。謝謝。
emptyList=[]
message=input("What Would You Like To Encrypt?\n")
messageLength=len(message)
for count in range(0,messageLength):
emptyList=[]
emptyList[count].append(message[count])
'的emptyList [0]'不'的時候是emptyList''[]'存在。你可能想'empyList.append(message [count])'。也就是說,執行'emptyList = list(message)'可能會更容易 – inspectorG4dget