-3

list[0:9] and list[1:10] were showing same in my python IDLE. I'm not sure the logic behind, could some one please explain. Please see the values retrieved below.

>>> list[0:9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list[0:10]
[1, 2, 3, 4, 5, 6, 7, 8, 9]

enter image description here

grg
  • 5,023
  • 3
  • 34
  • 50

1 Answers1

1

In the latter the second index is over the last element.

l = [1,2,3]
l[0:100]
=> [1,2,3]
Ursus
  • 29,643
  • 3
  • 33
  • 50