📘 Lesson  ·  Lesson 76

Palindrome Program

Palindrome Program in Python

A palindrome reads the same forwards and backwards, like "madam" or 121. This program checks for it.

Python Program

Python
word = "madam"
if word == word[::-1]:
    print(word, "is a Palindrome")
else:
    print(word, "is Not a Palindrome")

# For a number
num = 121
print("Number palindrome:", str(num) == str(num)[::-1])

Expected Output

madam is a Palindrome Number palindrome: True

How it Works

  • word[::-1] reverses the string using slicing.
  • If the reversed string equals the original, it is a palindrome.

Summary

  • A palindrome reads the same forwards and backwards, like "madam" or 121. This program checks for it.
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.