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?
3 Respostas
+ 2
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.
+ 2
SAIFULLAHI KHAMISU quick easy way is to use the built-in function reversed
print("".join(reversed(input())))
0
Yes, you can reverse a string without slicing by using a loop. Here are a couple of common ways to do it:
Method 1: Building a new string
* Create an empty string, which will store the reversed version.
* Loop through the original string from the last character to the first.
* In each iteration, append the current character to your new, empty string.
https://sololearn.com/compiler-playground/cT0FfX5ARhBu/?ref=app