为什么在试图以相同的逻辑方式访问不存在的索引时,“索引”的形状不同?
当调试一些我仍然不了解的错误时,我偶然发现了一件怪异的事情。
当我以两个逻辑上相似的方式访问列表,但通过代码不同的方式,以超出范围的索引,我在Pycharm的评估窗口中遇到了两个略有不同的错误。
看起来这样:
定义:
a = [1, 2, 3]
然后:
1)
a[111]
结果:
{IndexError}list index out of range
t = 111
a[t]
结果:
IndexError: list index out of range
当我在每个访问之前添加列表定义时,错误看起来与第二版相同。
它有意义吗?从中可以理解什么?
谢谢!
I have stumbled upon a weird (to me) thing when debugging some bug I still have not understood.
When I access a list in two logically similar, but code-wise different ways, in an index that is out of range, I get two slightly different errors in the Evaluation window in pycharm.
Looks like this:
definition:
a = [1, 2, 3]
then:
1)
a[111]
Result:
{IndexError}list index out of range
t = 111
a[t]
Result:
IndexError: list index out of range
When I add the list definition right before each access, the error looks the same, as the second version.
Does it have any significance? What can be understood from this?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论