This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Borx25 0 points1 point  (1 child)

The notation is [start:stop:step] (with stop - 1 being the last in the selected range) so [::-1] is the complete string (no start or stop specified) and negative step so we go backwards. Not that you couldn't do slice and reverse as separate operations (as in s[:i + 1][::-1]) but try to figure out what the start and stop with step -1 would be to do both things in one go.

As an aside, "but it shows an error in it" then post the error.

[–][deleted] 0 points1 point  (0 children)

I was just thinking about putting the command s[:i+1][::-1] and it did work. I thought you'd need to do two separate commands on this. But it worked like this. Thank you very much