我是新来的python,并有问题看到为什么这段代码不起作用。我希望它返回[10,122,2]。虽然循环python
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:列表索引超出范围”,但我的理解是,当条件满足while循环只运行。我错过了什么?谢谢
想想x会发生什么3 –