def reverse(str): res = '' def _reverse(): nonlocal res nonlocal str if len(str) > 0: res += str[-1] str = str[:-1] _reverse() _reverse() return res print(reverse("abcd"))
def reverse(s): if len(s) == 1: return s res = s[-1] + reverse(s[:-1]) return res print(reverse("abcd"))