Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Print all the "a" of a string on python

I’m trying to print all the "a" or other characters from an input string. I’m trying it with the .find() function but just print one position of the characters. How do I print all the positions where is an specific character like "a"

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can use find with while loop

a = "aabababaa"
k = 0
while True:
    k = a.find("a", k) # This is saying to start from where you left
    if k == -1:
        break
    k += 1
    print(k)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading