How Do You Write a Python Program to Test if a Word is a Substring of Another Word?

Problem scenario
You want to write a program that will test if a pattern is in another word. You are looking for the SQL equivalent of "contains" in Python. How do you test if a string is a substring of another word?

Solution
Use this program:

# Change "micro" and "microsoft" to the substring and string to be searched respectively:

a = "micro"
b = "microsoft"
if a in b:
  print(a + " is in " + b)
else:
  print(a + " is NOT in " + b)

Leave a comment

Your email address will not be published. Required fields are marked *