爲什麼這個工程:Python懶惰布爾評價出錯了?
s = 'xyz'
i = 0
while i < len(s) and s[i] not in 'aeiou':
print(s[i])
i += 1
x y z
...但是這不?
s = 'xyz'
i = 0
while s[i] not in 'aeiou' and i < len(s):
print(s[i])
i += 1
x y z Traceback (most recent call last): File "<pyshell#135>", line 1, in <module> while s[i] not in 'aeiou' and i <= len(s): IndexError: string index out of range
我很困惑,我缺少什麼嗎?
在'我[i]不在'aeiou'和我
2013-09-26 05:54:52
實際上標題應該是「懶惰的評估工作,如預期和記錄一樣。 – Hyperboreus