0

I found a code block and I don't understand the code.help me there...

txt = input("TYPE YOUR TEXT") print(txt[::-1])

2nd Apr 2021, 8:52 AM
Chinmoy Roy
Chinmoy Roy - avatar
4 odpowiedzi
+ 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' .
2nd Apr 2021, 9:38 AM
Scarlet Witch
Scarlet Witch - avatar
+ 2
::-1 use to reverse string
2nd Apr 2021, 8:57 AM
A͢J
A͢J - avatar
0
Explain me how does it work?
2nd Apr 2021, 8:59 AM
Chinmoy Roy
Chinmoy Roy - avatar
2nd Apr 2021, 1:38 PM
Hima
Hima - avatar