Answers for "count occurrences of a character in string python"


how to count the occurrence of a word in string python

# define string
string = "Python is awesome, isn't it?"
substring = "is"

count = string.count(substring)

# print count
print("The count is:", count)
Posted by: Guest on June-05-2020

count number of occurrences of character in string

public class CountStringOccurence {
public static void main(String[] args) {

int count= countOccurences("aaassssddadad",'s');


private static int countOccurences(String word, char character){
  int count = 0;
  for(int i = 0; i < word.length(); i++){
    if(word.chartAt(i) == character){
      count++; } 
      return count;
Posted by: Guest on January-22-2021

Code answers related to "count occurrences of a character in string python"

Python Answers by Framework

Browse Popular Code Answers by Language