Explain how the code works?

would you please explain how the code works? I mean word[::-1]

The subscript denotes a virtual slice consisting of all the characters but with a right to left step, meaning it begins on the right end and moves to the left end.

In literal terms,


but the relaxed syntax of the slice method permits us to leave out the start and end if we are slicing the entire word, hence, word[::-1].

1 Like