How to get the index of the third occurrence of specific character in string with Python

1 Answer

0 votes
s = 'python n n java python'
  
ch = 'n'

result = s.index(ch, s.index(ch, s.index(ch) + 1) + 1)
  
print(result)   
 
 
 
'''
run:
  
9
         
'''

 



answered May 11, 2020 by avibootz
...