I have a string "Queen" and I have the following code snippet:
string = "Queen"
print(string[::-1])
Surprisingly it gives the result "neeuQ". But when I do print(string[-1::0])
it says
ValueError Traceback (most recent call last)
<ipython-input-26-3b86270ea57d> in <module>
1 string = "Queen"
----> 2 print(string[-1::0])
ValueError: slice step cannot be zero
Again when I write print(string[-1::9])
or any other number>0 it shows the same result "n".
I understand this is about Python's string slicing properties but I didn't get the operations that are happening inside for every command. Normally for a string[0::4]
it's absolutely fine but what's happening in these cases? Why are we having such outputs?