I just wonder why slice [::-1]
is the same as [-1::-1]
?
Syntax for reference: [start:stop:step]
It's interesting because almost every Internet article about Python slices states that start defaults to 0. But it seems start defaults to -1 when a step is a negative number. I didn't find that information in the official Python Docs. Could someone clarify this?
Example:
lst = ['c', 'a', 't']
print(lst[0::-1])
print(lst[::-1])
print(lst[-1::-1])
Output:
['c']
['t', 'a', 'c']
['t', 'a', 'c']