Created
February 26, 2017 21:17
-
-
Save shreezan123/c6a1c583c9b173caa196926bd67d7b4a to your computer and use it in GitHub Desktop.
A confusion related to index of for loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''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