我是 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循环仅在满足条件时运行。我错过了什么?谢谢