I have the below code which takes and reverses a string. I can't understand a part from debugging the code. When the string length is being equal to 0, it goes into the if branch and returns string, immediately after that, the debugger goes into the else branch and regularly returns letters.
Please explain how is it that the code jumps from if statement into the else and regularly returns letters.
def func(mString: str):
if len(mString) == 0:
return mString
else:
print("Once")
return func(mString[1:]) + mString[0]
reversed_str = func("Hello")
print(reversed_str)
Tried to debug to see how it works but couldn't understand