← Python for Beginners
0 of 27 lessons done0%

Practice · Lesson 25 of 27

Practice: reverse and palindrome

A palindrome reads the same forwards and backwards: madam, level, racecar.

You already know how to reverse a string: word[::-1]. A word is a palindrome if it equals its reverse.

Try doing it with a loop too. It's a common interview follow-up: "now do it without slicing".

rev = ""
for ch in "abc":
    rev = ch + rev
print(rev)    # cba

Your task

Read a word. Print its reverse, then print Palindrome or Not palindrome.

For madam:

madam
Palindrome