0
I found a code block and I don't understand the code.help me there...
txt = input("TYPE YOUR TEXT") print(txt[::-1])
4 ответов
+ 7
when you do a[::-1], it starts from the end towards the first taking each element. So it reverses the list. This is applicable for lists/tuples as well.
Example -
Input:
txt = '1234'
print(txt[::-1])
Output:
'4321'
.
+ 2
::-1 use to reverse string
0
Explain me how does it work?
0
https://stackoverflow.com/questions/766141/understanding-string-reversal-via-slicing
I'd rather recommend to read this .