Articles → Python → Count string function in pythonCount string function in pythonIn this article, we will discuss count string function in python.Purpose Count function counts the number of occurrences of a given string in another string.Example Consider the following examplestr = "this is string example"
print ("number of occurrences of letter 'e' are:", str.count('e'))Here I want to check the occurrence of character ‘e’ in the string. Here ‘e’ comes twice in the word ‘example’. Now run the above code and you will get following output.Click to EnlargePosted By - Karan Gupta Posted On - Wednesday, February 20, 2019
Your Email Id
Characters remaining 250
str = "this is string example"
print ("number of occurrences of letter 'e' are:", str.count('e'))