{"id":24762,"date":"2021-11-02T09:46:05","date_gmt":"2021-11-02T04:16:05","guid":{"rendered":"https:\/\/python-programs.com\/?p=24762"},"modified":"2021-11-05T19:15:58","modified_gmt":"2021-11-05T13:45:58","slug":"python-string-count-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-string-count-method-with-examples\/","title":{"rendered":"Python String count() Method with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python String translate() Method with Examples<\/a>
\nString count() Method in Python:<\/strong><\/p>\n

The count() method returns the number of occurrences of a specified value in the string.<\/p>\n

Syntax:<\/strong><\/p>\n

string.count(value, start, end)<\/pre>\n

Parameters<\/strong><\/p>\n

value:<\/strong> This is Required. It is a string The value to look for in the string.<\/p>\n

start:<\/strong> This is optional. It is an integer. The starting point for the search. The default value is 0.<\/p>\n

end:<\/strong> This is optional. It is an integer. The ending point for the search. The default value is the end of the string.<\/p>\n

Return Value:<\/strong><\/p>\n

The count() method returns the number of times the substring(value) appears in the given string.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string = \"hello this is btechgeeks.good morning btechgeeks\"\r\nGiven value = \"btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

The no of occurences of { btechgeeks } in a given string =  2<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given string = \"good morning btechgeeks good\"\r\nGiven value = \"o\"\r\nstart position = 1\r\nend position = 13<\/pre>\n

Output:<\/strong><\/p>\n

The no of occurences of { o } in a given string =  3<\/pre>\n

String count() Method with Examples in Python<\/h2>\n