Lesson guide
What this Python exercise practices
Is Palindrome String is a beginner practice lesson that focuses on strings, formatting, traversal. It is designed to be solved in about 8 minutes with examples, starter code, and test feedback.
Prerequisites
- Python variables
- String values
- Basic indexing
Difficulty and time
- Level
- Beginner
- Estimated time
- 8 minutes
Summary
Determine whether a string reads the same forwards and backwards, ignoring non-alphanumeric characters and case.
Problem statement
Write a function is_palindrome(s) that returns True if the input string s is a palindrome when considering only alphanumeric characters and ignoring case; otherwise return False. An empty string (or a string with no alphanumeric characters) should be considered a palindrome.
Task
Practice conditional logic and simple string processing to detect palindromes.
Examples
Simple palindrome
Input
'racecar'
Output
True
Explanation
The string "racecar" reads the same forwards and backwards.
Input format
A single string argument s.
Output format
Return True if s is a palindrome (ignoring non-alphanumerics and case), otherwise False.
Constraints
Do not use external libraries. Handle empty strings and strings with punctuation.
Samples
Sample input 0
"A man a plan a canal Panama"
Sample output 0
True
Explanation 0
Ignoring spaces and case, it's a palindrome.
AI assistant
Ask me anything!
Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.
Chat history is temporary and will not be saved.
Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.