Index number of a letter which is present multiple times in a String!



sentence=("i love wearing  sunglasses and keds !!!")



Process finished with exit code 0

In the above mentioned string, there are two ‘d’ . When I used sentence.index(‘d’), it only returned the index number of first ‘d’.

How can I get the index number of all the ‘d’ ?


if you check documentation you will see .index() does just that

if you want all indexes, you will have to write your own code. You will need a data type allowing you to store multiple values (like a list), and then find a way to append to this list. The simplest approach would be a for loop and a if condition, but that is up to you


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.