How to find all the positions of a character in a string with Python

1 Answer

0 votes
s = "Python programming language"

ch = 'n'

print([pos for pos, char in enumerate(s) if char == ch])


     
     
'''
run:
     
[5, 16, 21]

'''

 



answered Apr 12, 2021 by avibootz
...