1message = 'python is popular programming language'
2
3# number of occurrence of 'p'
4print('Number of occurrence of p:', message.count('p'))
5
6>>> Number of occurrence of p: 4
1#printing the number of characters in a string
2print(len("String you want to count"))
3
4#counting characters in a variable
5a = "some string"
6print(len(a))
1def count_substring(string,sub_string):
2 l=len(sub_string)
3 count=0
4 for i in range(len(string)-len(sub_string)+1):
5 if(string[i:i+len(sub_string)] == sub_string ):
6 count+=1
7 return count
8