0

In Python, the equivalent of [the synntactic sugar] 'bottle'[1] is 'bottle'.__getitem__(1)

What is the equivalent method of 'bottle'[1:3] then?

multigoodverse
  • 7,638
  • 19
  • 64
  • 106
  • 2
    The same, but with a `slice` object as a parameter (`a:b(:c)` is syntactic sugar for creating a slice, but only in this context). Depending on the class, the method can accept an integer, string, slice, tuple, tuple of slices, or anything else. – tobias_k Mar 11 '20 at 09:42
  • 2
    Does this answer your question? [Python: Implementing slicing in \_\_getitem\_\_](https://stackoverflow.com/questions/2936863/python-implementing-slicing-in-getitem) – funnydman Mar 11 '20 at 09:43
  • `bottle[1:3]` means `bottle[ slice(1,3) ]` means `bottle.__getitem__( slice(1,3) )` – furas Mar 11 '20 at 09:45

0 Answers0