Index error: list assignment index out of range

使用 for 循环处理字符串、列表时,如果有 remove  del  pop等修改列表、字符本身的函数时,会出现 out of  range 的错误。

主要原因 : for循环开始后,列表的索引是固定的,不能改变。

                      使用这三个函数时,列表会不断地递补,改变索引的排列,从而造成错误。

解决办法:倒序使用索引。reverses(range(len(list)))

猜你喜欢

转载自blog.csdn.net/coolervschanger/article/details/79617175