0

I was wondering why the following that when I have list in python , lis Why does lis[1:3] only includes the 2nd and 3rd element of the list rather than 2nd, 3rd and 4th element?

Kamster
  • 127
  • 7

1 Answers1

0

One reason is that it makes it easier to extract a sublist of a certain length.

For instance, a[i:i+n] will extract the sublist of length n starting at element i of the list a.

This convention also dovetails with the way range(...) and xrange(...) work.

ErikR
  • 51,541
  • 9
  • 73
  • 124
  • ok, maybe I that makes it a little clearer why they use that convetion. I guess just first glance I would expect it to go other way – Kamster Oct 09 '15 at 20:16