Check Palindrome String
Check if string is palindrome.
BeginnerPhase 5 - Category 1: Basic String HandlingExample 8 of 10
check-palindrome-string.py
1# Take string input2s = input("Enter a string: ")34# Check palindrome5if s == s[::-1]:6 print("Palindrome")7else:8 print("Not a palindrome")
Output
Enter a string: racecar Palindrome Enter a string: hello Not a palindrome
What's going on
Compare string with its reverse.
Key Concepts:
Reverse string using slicing
Compare with original
If equal, palindrome
🔗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