0
Could anyone explain this code? I'm lost...
2 Answers
+ 3
Junior Coder
That's called recursion which means call function again and again untill the condition met so in else part we are calling function and adding 1st character each time in reverse order.
spell(txt[1:]) + txt[0]
Suppose you have entered 'anant'
Here 1st character is 'a'
and txt[1:] will give nant
So spell('nant') + 'a'
Now here 1st character is n
And 'nant'[1:] = 'ant'
So now spell('ant') + 'n' + 'a'
Just repeat it untill txt become ''' means empty
So spell('nt') + 'a' + 'n' + 'a'
spell('t') + 'n' + 'a' + 'n' + 'a'
't' + 'n' + 'a' + 'n' + 'a'
= tnana
+ 1
A͢J Thanks đ