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 strings2s1 = input("Enter first string: ")3s2 = input("Enter second string: ")45# Check substring6if 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
🔗Related Content
- 📖
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- 💻
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum