Example 1: Using a for loop
Output
2
In the above example, we have found the count of 'r' in 'nodmek'. The for-loop loops over each character of my_string and the if condition checks if each character of my_string is 'r'. The value of count increases if there is a match.
Example 2: Using method count()
Output
2
count() counts the frequency of the character passed as parameter.