Removing a character from a string I am asked the following:
def myRemove( str, ch ):
 # Return a new string with the first occurrence of ch removed.  If there is none, return str.

Sample run
&gt;&gt;&gt; myRemove( &quot;abcdabcd&quot;, &quot;a&quot;)
'bcdabcd'
&gt;&gt;&gt; myRemove( &quot;abcdabcd&quot;, &quot;x&quot;)
'abcdabcd'
&gt;&gt;&gt; myRemove( &quot;abcdabcd&quot;, &quot;d&quot;)
'abcabcd'

I have tried a few different methods but have not been able to figure the problem out. Here is my attempt:
def myRemove( str, ch ):
    for num in range (0, len(str)):
        if (str[num] == ch):
            return str[0:num] + str[num + 1:]
        else:
            return str

There is also an extension to this problem which asks : Return a new string with all occurrences of ch removed. If there are none, return str. However, since I have not been able to solve the first part, naturally I was not sure how to solve the second. Would appreciate any guidance.
Notice that the loop will only occur once! In the beginning num will be 0. At this point, we enter the if statement:

if we got that str[0] == ch (notice that num==0 and thus str[0]==str[num]), then we return some string
otherwise we return another string

The important thing here, is that no matter what - we will quit in the first iteration of the for loop.
To fix this, consider placing the return str outside the for loop (without else as well)