Check if Substring Exists

Check if one string is substring of another.

IntermediatePhase 5 - Category 5: Advanced String LogicExample 2 of 14
check-if-substring-exists.py
1# Take two strings
2s1 = input("Enter first string: ")
3s2 = input("Enter second string: ")
4
5# Check substring
6if s2 in s1:
7 print(f"{s2} is substring of {s1}")
8else:
9 print(f"{s2} is not substring of {s1}")

Output

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

What's going on

Use 'in' operator to check substring.

Key Concepts:

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