【发布时间】:2020-05-11 09:05:16
【问题描述】:
Python 没有给我这个 for 循环的索引错误:
s = ['one', 'two']
for index, char in enumerate(s):
if s[index - 1] != ' ' or s[index + 1212] != ' ':
pass
但是交换条件后它确实给了我一个索引错误:
s = ['one', 'two']
for index, char in enumerate(s):
if s[index + 1212] != ' ' or s[index - 1] != ' ':
pass
有人愿意解释一下吗?
【问题讨论】:
标签: python-3.x for-loop enumerate