word = "hello"
word[::-1][::-1][::-1]
I see that it reverses word with slices when put through an interpreter, but how exactly does this work with three []?
word = "hello"
word[::-1][::-1][::-1]
I see that it reverses word with slices when put through an interpreter, but how exactly does this work with three []?
word = "hello"
word[::-1][::-1][::-1]
This is equivalent to:
word = "hello"
word = word[::-1]
word = word[::-1]
word[::-1]
Easy subscript ([]) works on the results of the previous. We could also make this more explicit with parentheses.
word = "hello"
( ( word[::-1] )[::-1] )[::-1]
In this case, the string is reversed, then that reversed string is reversed back to the original order, then it's reversed again. The word "overkill" comes to mind.