Count occurrences of a substring in a string.

In this program, we will take a string and substring as input and count occurrences of a substring in a string.

Steps to solve the program
  1. Take a string and substring as input.
  2. Count the occurrences of a substring in a string using count().
  3. Print the output.
				
					#Input string
string = "sqatoolspythonspy"
sub = "spy"

#Printng output
string.count("spy")
				
			

Output :

				
					2
				
			

reverse a string if it’s length is a multiple of 4.

test whether a passed letter is a vowel or consonant.

Leave a Comment