Oh,I have just thinked that the max index equals the length of the list, but python supports more index.
2013/8/21 eryksun <eryk...@gmail.com> > On Tue, Aug 20, 2013 at 3:31 PM, Walter Prins <wpr...@gmail.com> wrote: > > On 20 August 2013 10:20, sikonai sikonai <tanjyu...@gmail.com> wrote: > >> > >> >>> list=[1,2,3,4,5,6,7,8,9] > >> >>> list[9:0:-2] > >> [9, 7, 5, 3] > >> >>> list[10:0:-2] > >> [9, 7, 5, 3] > > > > For the specific list you show, the 2 expressions yield the same result. > > However this does not mean that this is true of any list. The reason > the 2 > > expressions return the same result is because the starting index for the > > slice operation is effectively capped at 9, due to the list containing > only > > 9 elements, so hence any value above 9 in the first slice parameter is > > essentially reset/capped to 9. > > The start index is capped at 8: > > >>> slice(9, 0, -2).indices(9) > (8, 0, -2) >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor