Python String | Check if substring is in string or not.

In this program, we will take a string as input and check if the substring is in string or not.

Steps to solve the program
  1. Take a string and substring as input.
  2. Convert them into two different lists using split() and create a count variable and assign its length equal to 0.
  3. Use for loop to check whether a word from the substring is in the given string.
  4. If yes, then add 1 to the count variable each time.
  5. In the end, if the value of the count variable is equal to the length of the list containing the substring print yes else print no.
				
					#Input strings
str1 = "I live in Pune"
str2 = "I live"

list1 = str1.split(" ")
list2 = str2.split(" ")
count = 0

for word in list2:
    if word in list1:
        count += 1
        
#Printing output
if count == len(list2):
    print("Yes")
else:
    print("No")
				
			

Output :

				
					Yes
				
			

generate a random binary string of a given length.

find all substring frequencies in a string.

Leave a Comment