Hello everyone! Today we are going to see how can we count the occurrences of a character in a given string using Python. Python provides a library method count which can be used to count the occurrence of a substring in a given string. Below code snippet takes a character as a substring and returns the count of that in the source string. # Enter the string in which we need to search sentence = input ( "Enter a string \n " ) # Enter a string/character which needs to be searched sub_string = input ( "Enter the substring to search \n " ) # Getting the count of the sub string in source string - convert both to lowercase if we want to count irrespective of case count_of_substring = sentence . lower () . count ( sub_string . lower ()) # Print the count of the substring in the source string print ( 'Count of ' + sub_string + ' in ' + sentence + ' is ' + str ( count_of_substring )) The output of this program will be