Check if Substring Exists

Check if one string is substring of another.

Logic BuildingIntermediate
Logic Building
# Take two strings
s1 = input("Enter first string: ")
s2 = input("Enter second string: ")

# Check substring
if s2 in s1:
    print(f"{s2} is substring of {s1}")
else:
    print(f"{s2} is not substring of {s1}")

Output

Enter first string: Hello World
Enter second string: World
World is substring of Hello World

Use 'in' operator to check substring.

Key Concepts:

  • 'in' operator checks membership
  • Returns True if substring exists
  • Simple check