0
How can I reverse a string without using slicing?
If I have a string like "python", I know I can do s[::-1] to reverse it. But what if I want to reverse it without slicing? Can I do it with a loop?
2 Answers
+ 1
You can always iterate through the string backwards (using the starting index as string end, and decrementing it). As you go through every character from end to start of the string, simply append it to a new string.
+ 1
SAIFULLAHI KHAMISU quick easy way is to use the built-in function reversed
print("".join(reversed(input())))