Python 3.x 为什么枚举不给我一个索引错误?

Python 3.x 为什么枚举不给我一个索引错误?,python-3.x,for-loop,enumerate,Python 3.x,For Loop,Enumerate,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] != '

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)中,布尔表达式一次计算一部分,一旦其中一部分为false,计算就会停止。这称为“最小评估”

在您的情况下,如果
s[index-1]!=''
为false,则
s[index+1212]!=''根本不会被计算,这反过来也不会产生错误。

这是因为