+ 1

I am unable to understand the output correctly. plz help me out

squares = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] print(squares[-5:5]) print(squares[-5:6]) print(squares[-5:7]) print(squares[-5:8]) print(squares[-5:9]) print(squares[-5:10]) print(squares[6:-4]) print(squares[6:-3]) print(squares[6:-2]) print(squares[6:-1]) print(squares[6:-0]) Output: [] [25] [25, 36] [25, 36, 49] [25, 36, 49, 64] [25, 36, 49, 64, 81] [] [36] [36, 49] [36, 49, 64] []

2nd Aug 2019, 3:56 AM
Dhyey Badheka
Dhyey Badheka - avatar
2 odpowiedzi
+ 11
We have list [x: y: z]. The sheet always counts from x to y in increments of z (default is z = 1). If x or y has a negative sign, then their position is counted from the end of the list. The first element of the list has position 0, the last element of the list has position - 1. If x and y refer to the same element, we get an empty list []
2nd Aug 2019, 4:25 AM
Mikhail Gorchanyuk
Mikhail Gorchanyuk - avatar
+ 4
This may give you some ideas https://code.sololearn.com/cXNzv56rgiyL
2nd Aug 2019, 4:32 AM
David Ashton
David Ashton - avatar