Complete the code to check if a string is the same forwards and backwards.
def is_palindrome(s): return s == s[1]
[1:] or [:1] which do not reverse the string.Using [::-1] reverses the string, so comparing s to s[::-1] checks if it reads the same backwards.
Complete the code to ignore case when checking palindrome.
def is_palindrome(s): s = s.lower() return s == s[1]
After converting to lowercase, reversing with [::-1] allows case-insensitive palindrome check.
Fix the error in the code to correctly check palindrome ignoring spaces.
def is_palindrome(s): s = s.replace(' ', '') return s == s[1]
Removing spaces and then reversing with [::-1] checks palindrome ignoring spaces.
Fill both blanks to create a palindrome check ignoring case and non-alphanumeric characters.
import re def is_palindrome(s): s = re.sub([1], '', s).lower() return s == s[2]
Using regex '[^a-zA-Z0-9]' removes all non-alphanumeric characters. Then reversing with [::-1] checks palindrome ignoring case and special characters.
Fill all three blanks to create a palindrome check ignoring case, spaces, and punctuation.
import string def is_palindrome(s): s = ''.join(c for c in s.lower() if c not in [1]) return s == s[2] and len(s) > [3]
Removing punctuation and spaces using string.punctuation + ' ', reversing with [::-1], and checking length greater than 0 ensures a valid palindrome check.