Articles → Python → Count String Function In PythonCount String Function In PythonIn this article, we will discuss the count string function in Python.Purpose The 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 the character ‘e’ in the string. Here ‘e’ comes twice in the word ‘example’. Now run the above code and you will get the following output.Posted By - Karan Gupta Posted On - Wednesday, February 20, 2019 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
str = "this is string example" print ("number of occurrences of letter 'e' are:", str.count('e'))
Query/Feedback