Editor

Palindrome Checker

Advanced · Write the code · from Python Slicing: Master Indexing for Strings, Lists, and Tuples

From the lesson: Python Slicing: Master Indexing for Strings, Lists, and Tuples

Imagine a pizza cut into 8 slices, numbered 0 through 7. You don't always want the whole pizza. Sometimes you want slices 2 through 5. Sometimes you want every other slice. Sometimes you want the last three slices.

Read the lesson

Write a function called is_palindrome(text) that returns True if the text reads the same forwards and backwards, and False otherwise. Use slicing to reverse the string. Convert the text to lowercase first so the check is case-insensitive.

Test it with these calls:

print(is_palindrome('racecar'))
print(is_palindrome('Python'))
print(is_palindrome('Madam'))
def is_palindrome(text):
# Convert to lowercase and check if it equals its reverse
pass
print(is_palindrome('racecar'))
print(is_palindrome('Python'))
print(is_palindrome('Madam'))

More Slicing exercises

All Python exercises · 50 practice problems · Data Structures quiz