python count occurrences in string index method code example Example: python count character occurrences str1.count("a")