古詩詞大全網 - 成語查詢 - python中出現string index out of range是為什麽

python中出現string index out of range是為什麽

報錯應該是列表超出範圍了,比如

s='hello?world'?#s長度為11

print?s[0]

>>>?h

print?s[10]

>>>?d

print?s[100]

>>>?IndexError:?string?index?out?of?range

前面2個會正常返回結果,最後壹個就會報錯超出範圍