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?

29th Jul 2025, 10:49 PM
SAIFULLAHI KHAMISU
SAIFULLAHI KHAMISU - avatar
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.
29th Jul 2025, 11:15 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
SAIFULLAHI KHAMISU quick easy way is to use the built-in function reversed print("".join(reversed(input())))
30th Jul 2025, 12:11 AM
BroFar
BroFar - avatar