简体   繁体   English

IndexError:超出范围的字符串索引不断出现

[英]IndexError: string index out of range keeps coming up

I am learning the app Jar module so I decided to make an encoder but I keep getting this error and I don't get what it means.我正在学习应用程序 Jar 模块,所以我决定制作一个编码器,但我不断收到此错误,我不明白它的含义。 I have looked it up on here and it talks about indexes but I haven't got any I don't think.我在这里查过它,它谈到了索引,但我没有任何我认为的。 My code is below an I hope you can help.我的代码在下面,希望你能帮忙。 This is the error这是错误

Note that indexes in string in Python starts from 0 (index of the first symbol) and ends with len(string) - 1 (index of last symbol).请注意,Python 中 string 中的索引从0 (第一个符号的索引)开始,以len(string) - 1 (最后一个符号的索引)结束。 In your code, you have counter <= numLetters , so you have error trying access symbol with counter index while the maximum index is counter - 1 , use counter < numLetters instead.在您的代码中,您有counter <= numLetters ,因此您在尝试使用counter索引访问符号时出错,而最大索引为counter - 1 ,请改用counter < numLetters

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM