Skip to content

Instantly share code, notes, and snippets.

@shreezan123
Created February 26, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shreezan123/c6a1c583c9b173caa196926bd67d7b4a to your computer and use it in GitHub Desktop.
Save shreezan123/c6a1c583c9b173caa196926bd67d7b4a to your computer and use it in GitHub Desktop.
A confusion related to index of for loop.
'''The code is meant to skip adding the character "a" and any other character that comes after "a". For this, I check if string's [i th] index = a, and add 1 to index, so that new index will be able to skip the character coming after "a". But this does not seem to be happening. Why is it so ?'''
str1 = "abcde"
str2 = ""
for i in range(len(str1)):
if str1[i] == "a":
i +=1
continue
else:
str2 += str1[i]
print (str2)
#Output is bcde. But why ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment