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])
2 Answers
+ 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.
0
print
49
25
list hasn't less than zero