1. 程式人生 > >Python常見錯誤:IndexError: list index out of range

Python常見錯誤:IndexError: list index out of range

spa bsp lis 遍歷字典 pan nbsp exe 字典 dex

用python寫腳本查詢字典時,在遍歷字典時循環到某一項時老是報錯

出現這種錯誤有兩種情況:

第1種可能情況

list[index]index超出範圍

第2種可能情況
list是空值就會出現

IndexError: list index out of range

第二種情況尤為難以排除錯誤

Python常見錯誤:IndexError: list index out of range