2

I see how "String"[::-1] works to return "gnirtS"

But isn't this supposed to be compatible with the slice function?

"String"[slice(-1, 0, -1)] ?

This returns "gnirt"

Barmar
  • 741,623
  • 53
  • 500
  • 612

1 Answers1

2

slice(-1, 0, -1) is not equivalent to [::-1]. slice(None, None, -1) is.

class SliceNotationTranslator:
    def __getitem__(self, item):
        print(item)

s = SliceNotationTranslator()
s[::-1]

Outputs

slice(None, None, -1)
DeepSpace
  • 78,697
  • 11
  • 109
  • 154