Solution 1

def reverse_string(a_string):
    result = ''
    for idx in range(len(a_string) - 1, -1, -1):
        result += a_string[idx]
    return result

Solution 2

def reverse_string(a_string):
    result = ''
    for idx in range(0, len(a_string)):
        result += a_string[len(a_string) - 1 - idx]
    return result

Solution 3

def reverse_string(a_string):
    return a_string[::-1]

Reverse a string

Write a function reverse_string that receives a string and returns it reversed. Example:

reverse_string('Hello World')  # 'dlroW olleH'
reverse_string('Python')  # nohtyP

Test Cases

test with large string - Run Test

def test_with_large_string():
    assert reverse_string('Python is Awesome') == 'emosewA si nohtyP'

test with short string - Run Test

def test_with_short_string():
    assert reverse_string('Python') == 'nohtyP'
def reverse_string(a_string): pass