IndexError: list index out of range in python for strings
问题 I wanted to remove the word "hello" from this array, but I get the "index out of bounds" error. I checked the range of len(token) ; it was (0,5) . Here is the code: token=['hi','hello','how','are','you'] stop='hello' for i in range(len(token)): if(token[i]==stop): del(token[i]) 回答1: You're getting an index out of bounds exception because you are deleting an item from an array you're iterating over. After you delete that item, len(token) is 4, but your for loop is iterating 5 times (5 being