-3

I have the following tuple:

tuple = (65,67,5,67,34,76,67,231,98,67)

When I did the following:

print tuple3[2:8]

I got:

(5, 67, 34, 76, 67, 231)

I thought that 98 should be also included. Isn't 98 on the index number 8? Why isn't 98 included?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • 1
    Slicing is [included:excluded]. This allows for things like `slicable[i:len(sliceable)]` – C.B. Dec 08 '15 at 19:21
  • 1
    https://docs.python.org/3/tutorial/introduction.html#lists – Sven Marnach Dec 08 '15 at 19:24
  • 1
    Why the downvotes? Question is well formulated and answerable. It's quite clearly a dupe as noted above, but not a bad question *per se*. –  Dec 08 '15 at 19:27
  • 1
    @Tibo: NMDV, but one DV criterion is "does not show any research effort", and every tutorial on Python's slice notation explains this. – DSM Dec 08 '15 at 19:35

1 Answers1

2

For a tuple or list - x[start:end], slicing in python begins at start and runs till end-1.

That is the reason 98 is not included in your code

KartikKannapur
  • 973
  • 12
  • 19