Practice Makes Perfect - reverse


What's wrong with this???

def reverse(text):
     newtext = ""
    for letter in text:
    text = newtext
    return text

I get a " Your code looks a bit off--it threw a "'str' object has no attribute 'insert'" error"
please help :slight_smile:


strings are immutable in python, .insert() is for list


Thank you very much! Is there a way to define my result variable as a list and then change it into a string?


well, you can always loop over the list (contain the reversed string) and add them (+) to a string, but personally i would use .join() for this


Thanks! I'll try it.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.