I'm teaching myself how to program in Python. I've never programmed before, so forgive me for my stupidity. Here's the code that I'm trying to figure out (from a book that I'm using):
I understand that the string's being sliced, but I can't figure out how each element of the string is returned in reverse order. Recursion sucks.
Code:
def reverse(s):
if s == "":
return s
else:
return reverse(s[1:]) + s[0]
I understand that the string's being sliced, but I can't figure out how each element of the string is returned in reverse order. Recursion sucks.