{"id":5649,"date":"2023-10-28T10:41:33","date_gmt":"2023-10-28T05:11:33","guid":{"rendered":"https:\/\/python-programs.com\/?p=5649"},"modified":"2023-11-10T12:05:10","modified_gmt":"2023-11-10T06:35:10","slug":"count-occurrences-of-a-single-or-multiple-characters-in-string-and-find-their-index-positions","status":"publish","type":"post","link":"https:\/\/python-programs.com\/count-occurrences-of-a-single-or-multiple-characters-in-string-and-find-their-index-positions\/","title":{"rendered":"Count Occurrences of a Single or Multiple Characters in String and Find their Index Positions"},"content":{"rendered":"

A Python string is a collection of characters surrounded by single, double, or triple quotes. The computer does not understand the characters; instead, it stores the manipulated character as a combination of 0\u2019s and 1\u2019s internally.<\/p>\n

In this article we are going to count single characters \/multiple characters in a given string.<\/p>\n

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

1)Count occurrences of single characters in a given string<\/strong><\/p>\n

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

given_string=\"btechgeeks\" character ='e'<\/pre>\n

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

count of  e is : 3<\/pre>\n

2)Count occurrences of multiple characters in a\u00a0 given string<\/strong><\/p>\n

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

given_string=\"btechgeeks\" character =['e' , 'c' , 's' ]<\/pre>\n

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

count of  e is : 3\r\ncount of  c is : 1\r\ncount of  s is : 1<\/pre>\n

Count occurrences of single\/multiple characters in a given string and indices of them<\/strong><\/h2>\n

There are several methods\u00a0 some of them are:<\/p>\n