簡體   English   中英

這個 Python 代碼中的 [:5] 和 [5] 有什么區別?

[英]What's the difference between [:5] and [5] in this Python code?

這個 Python 代碼中的[:5][5]什么區別?

y_test_predicted = model.predict(X_test)

residuals = Y_test   -   y_test_predicted

print(residuals[:5])

print(residuals[5])

您可以在此鏈接中找到有關切片的有用信息。

參考下面的簡單例子,一目了然:

list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j']
print(list[5]) #it will print: f
print(list[:5]) #it will print:  ['a', 'b', 'c', 'd', 'e'], indices form 0 to 4
#List Slicing: list[start:stop:step]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM