+ 3
because 'i' is getting value from the copy of the string which is made by for loop, and the string you search index is diffrent and totally converted into '....' In the last iteration, when 'i' is 1 from the copy of string ( gen. by for loop ), the 'last' string is already '....' and do not contains 'i' i.e., 1 so the compiler raises the value error. use try ... except to catch that error ``` test = "1231" for i in test: print (test) print (i) try: index = test.index(i) print(index) test = test.replace(i, ".") except : print("string 'test' has no '{0}'".format(i)) ```
1st Sep 2022, 1:25 AM
Abhay
Abhay - avatar