When you make a return
call within the function, the control comes back to parent (which executed the function) ignoring the code within the scope of function after return
. In your case, that is why print
is not getting executed by your code.
Move the line containing print
before return
and move return
to outside of the for
loop. Your code should work then.
Suggestion:
There is simpler way to reverse the string using ::-1
. For example:
>>> my_string = 'HELLO'
>>> my_string[::-1]
'OLLEH'
1
solved string reversal function using reversed indexing