0

slice list

Please, could any help with this code, Im trying get the ideia how this works test = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] print(test[7:5:-1])

9th Aug 2016, 6:56 PM
Antônio Alexandre Neto
Antônio Alexandre Neto - avatar
2 odpowiedzi
+ 3
the index (between the [ ]) had three parts: first number stands for the startindex, here it is 7, which corresponds to test[7]=49. second number stands for end index, it is test[5]=25. third number is the stepsize of the range: -1 means reversed. So test[7:5:-1] = [49,36]. remark: Python works with zero based indexing. remark: the end index is never included.
9th Aug 2016, 8:01 PM
Jochem Boersma
0
print 49 25 list hasn't less than zero
19th Sep 2016, 4:35 PM
Wai Hlyan Htun
Wai Hlyan Htun - avatar