此Python代码中[:5]和[5]有什么区别?

时间:2020-09-08 08:21:03

标签: python linear-regression train-test-split

此Python代码中的[:5][5]有什么区别?

y_test_predicted = model.predict(X_test)

residuals = Y_test   -   y_test_predicted

print(residuals[:5])

print(residuals[5])

1 个答案:

答案 0 :(得分:0)

您可以在此link中找到有关切片的有用信息。

请参考以下简单示例以了解它:

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]
相关问题