天天看點

Python:IndexError: list index out of range

Python3.x

一、範圍問題

value無對應的index,造成越界

解決:增加臨界判斷語句,或者采取+-1

二、

list為空,當list[0]會出現該錯誤

三、資料問題

如下處理檔案時,檔案有空行

lenses=[inst.strip().split('\t') for inst in fr.readlines()]
           

解決:删除空行。