-5

I need a simple and effective algorithm to reverse a string (for example: WelCome to emoCleW ).

I tried a loop:

s=input("Enter String To Be Reversed:")
    for i in range(len(s)+1,-1,-1):
        print(str1[0:i])

but this didn't work for me

StardustGogeta
  • 3,331
  • 2
  • 18
  • 32
  • Different ways of [Reversing a String](https://www.journaldev.com/23647/python-reverse-string). You can see the execution time of each method at the end of the article. – 000102 Jul 31 '19 at 14:39

1 Answers1

0

Like this:

s=input("Enter String To Be Reversed:")
print(s[::-1])
Carsten
  • 2,765
  • 1
  • 13
  • 28
  • Why would this be downvoted? – Carsten Jul 31 '19 at 14:39
  • I'm sorry, I downvoted this and forgot to give an explanation. There's nothing wrong with your answer, but I'm just not sure it adds anything to the more than two dozen answers on the duplicate question linked above (https://stackoverflow.com/questions/931092/reverse-a-string-in-python). Does that make sense? – StardustGogeta Jul 31 '19 at 18:28