IndexError: list index out of range and python

后端 未结 8 2360
醉酒成梦
醉酒成梦 2020-11-22 04:58

I\'m telling my program to print out line 53 of an output. Is this error telling me that there aren\'t that many lines and therefore can not print it out?

8条回答
  •  时光取名叫无心
    2020-11-22 05:11

    Yes,

    You are trying to access an element of the list that does not exist.

    MyList = ["item1", "item2"]
    print MyList[0] # Will work
    print MyList[1] # Will Work
    print MyList[2] # Will crash.
    

    Have you got an off-by-one error?

提交回复
热议问题