I am checking for single quotation (') and printing its index, output is always 0
S="'abc','dsd''eeee'"
for i in S:
    if(i=="'"):
        print(S.index (i))
how to get 0,4....?
I am checking for single quotation (') and printing its index, output is always 0
S="'abc','dsd''eeee'"
for i in S:
    if(i=="'"):
        print(S.index (i))
how to get 0,4....?
 
    
     
    
    str.index() only finds the first occurrence. Use enumerate instead.
for idx, i in enumerate(S):
    if i == "'":
        print(idx)
 
    
    You can use the re regular expression library for matching:
import re
pattern = r"'"
text = "'abc','dsd''eeee'"
indexes = [match.start() for match in re.finditer(pattern, text)]
 
    
    Here is a one-liner using list comprehension -
S="'abc','dsd''eeee'"
[i[0] for i in enumerate(S) if i[1] == "'"]
[0, 4, 6, 10, 11, 16]
