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

Why is my python find() function finding more values than in the string?

This is my code:

tempStorage = 'GOOD.LUCK'
print(tempStorage.find("."))

Instead of outputting 1, it outputs 4. Can someone tell me why?

Edit – I’m stupid, I confused count() with find()

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

>Solution :

You’re using str.find() which tells you the position.

You should use str.count() instead which counts the number of occurrences.

tempStorage = 'GOOD.LUCK'
print(tempStorage.count("."))
>>> 1
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