a='12345'
print(a[::1]) : index starts with 0
Output : 12345
print(a[::-1]) : index starts with -1 ,
Output : 54321
Output should be 15432 , index must start as usual with 0
a='12345'
print(a[::1]) : index starts with 0
Output : 12345
print(a[::-1]) : index starts with -1 ,
Output : 54321
Output should be 15432 , index must start as usual with 0
Python's indexing operator works as follows:
[start:end:step]
I assume when you ask about starting with 0, you mean the first argument. It's true that to get the first character you would need to do
>>> string = "12345"
>>> string[0]
'1'
But what is being done here is that the step is being modified, because the first two arguments are left empty, so are assigned to default values. A step of 1 just means that each character will be selected in order, so nothing changes. A step of 2 would print every other character:
>>> string[::2]
'135'
and a step of -1 moves through the string backwards and prints it in reverse as you showed.