Written by Sai Sameera Thota on March 19, 2013 in Programming > Python

Python Program to Reverse a String

GET ALERTS:

Get our Latest updates delivered to your mailbox!

Today we’ll discuss on Python program to Reverse a given String. First we are finding the length of the given string and storing it in the variable i and we are iterating it with the help of a while and adding the strings to the rev variable.

def reverse(string):

    i = len(string)
    rev = ""
    while i != 0:
        rev = rev + string[i-1]
        i = i - 1
    return rev


print(reverse("string"))

Output:
reverse

{ 2 comments… read them below or add one }

Akash January 24, 2016 at 4:40 am

Your code really helped me
thanks .

Reply

Sneha September 7, 2017 at 9:53 am

Your code really helped me
Thank You

Reply

Leave a Comment

Previous post:

Next post: