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"
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"
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)