我是新來的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 –