Hello everyone, in this tutorial we’ll see different ways to reverse string in Python. As we know, we can reverse a list using reverse() method but Python doesn’t have the reverse() method for string. Here are some alternate and easy ways to reverse a string. Ways to Reverse String in Python 1. Using Loop string1 = "the crazy programmer" string2 = "" i = len(string1)-1 while(i>=0): string2 = string2 + string1[i] i = i-1 print "original = " + string1 print "reverse = " + string2 Output: original = the crazy programmer reverse = remmargorp yzarc eht In above program, we’ve started a loop from the last index (length-1) to first index (0) of string1. In each step of loop, it will pick the character from right-side in string1 and concatenate with string2. 2. Using Recursion def reverse_it(string): if len(string)==0: return string else: return reverse_it(string[1:]) + string[0] print "added " + stri...
Just4Programmers can be described as a private limited company that develops softwares. Kayleigh Baxter who is the current Managing Director established it in early 1997. For several years now, Just4Programmers has been a proud Microsoft Gold Partner. This is to mean that it displays the best expertise and competence with regard to Microsoft technologies and also in relation to being an Amazon Web Services specialist.