【发布时间】:2013-05-17 09:38:26
【问题描述】:
我是 python 新手,在理解为什么这段代码不起作用时遇到问题。我希望它返回 [10,122,2]。
close = [5000,5010,5132,5134]
def difference():
x = 0
data = []
while x < len(close):
diff = close[x+1]-close[x]
data.append(diff)
x = x + 1
return data
它返回“IndexError: list index out of range”,但我的理解是 while 循环仅在满足条件时运行。我错过了什么?谢谢
【问题讨论】:
-
想想当 x 为 3 时会发生什么
标签: python while-loop