Hackbright Code Challenges

Reverse a String: Solution

Reverse a String: Solution

Problem

Reverse a String

Whiteboard

Easier

Concepts

Loops, Strings

Download

rev-string-solution.zip


def rev_string(astring):
    """Return reverse of string.

    You may NOT use the reversed() function!
    """

    # START SOLUTION

    out = ""

    for i in range(len(astring), 0, -1):
        out += astring[i - 1]

    return out