string reversal function using reversed indexing
<p>Could someone please help me understand why the following function does not print out the reverse of the string? What am I doing wrong?</p>

<pre><code>def myReverse(data):
    for index in range( len(data)-1, -1, -1 ):
        return data[index]
        print( data[index] )

myReverse('blahblah')
</code></pre>

<p><em>Intro:</em> the execution of a <code>for</code> loop will stop once a <code>return</code> statement or <code>break</code> statement is encountered or there is an exception.</p>

<p>You have a <code>return</code> statement which makes the <code>for</code> loop stop (<em>returning</em> control to the caller) as soon as the statement is encountered in the first iteration.</p>

<p>Move the <code>return</code> statement outside the <code>for</code> loop</p>

python