简体   繁体   中英

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

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

y_test_predicted = model.predict(X_test)

residuals = Y_test   -   y_test_predicted

print(residuals[:5])

print(residuals[5])

you can find a useful information about slicing in this link .

Refer to below simple example to understand it as a glimpse:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM