0

Could anyone explain this code? I'm lost...

https://code.sololearn.com/c97Sczefz3o8/?ref=app

3rd Jul 2022, 6:31 AM
Junior Coder
Junior Coder - avatar
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
3rd Jul 2022, 7:08 AM
A͢J
A͢J - avatar
+ 1
A͢J Thanks 👍
3rd Jul 2022, 10:12 AM
Junior Coder
Junior Coder - avatar