Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Is Palindrome String

Determine whether a string reads the same forwards and backwards, ignoring non-alphanumeric characters and case.

Python practice8 minControl Flow (If–Else Logic)BeginnerLast updated March 15, 2026

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

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 1

Input

"A man a plan a canal Panama"

Output

True

Ignoring spaces and case, it's a palindrome.