0

List slicing

a=[1,2,3,4,5,6] print(a[1:-1]) the output is[2,3,4,5] can anyone explain why? it is giving that output

18th Oct 2018, 12:02 PM
Rakesh Kumar N
Rakesh Kumar N - avatar
1 ответ
0
remember, array start from 0, when you're passing 1 as lower bound it start at 2. if negative value given, the lower bound would be lastindex-value, last index is 5 (because its start from 0) so its 5-1= 4, so lower bound is element number 4. which is 5. index 0 1 2 3 4 5 value [1,2,3,4,5, 6]
18th Oct 2018, 12:44 PM
Taste
Taste - avatar