7.String reverse, HELP


I designed this question using empty string and len(), but it always falls, I have check the range of the index and loop, it's ok.
However, it prompts

Oops, try again.
Does your reverse function take exactly one argument (a string)?

Your code threw a "'str' object does not support item assignment" error.

I have read many solutions on forums, some are easy to understand like string addition and using subtraction to construct the range. This forum is really a good discussion platform.
Here is my code below.

def reverse(text):
    empty = ""
    turn = len(text) - 1
    begin = 0
    for a in text:
        empty[turn] = text[begin]
        begin += 1
        turn -= 1
    return empty


Item assignment is you trying to use empty like a list.

I would actually change empty into a list, then join it at the end.


I see, thank you, seems I mixed it with pointer in C.