📘 Lesson  ·  Lesson 76

Palindrome Program

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.

Palindrome Program in Python

Palindrome आगे और पीछे से एक जैसा पढ़ा जाता है, जैसे "madam" या 121। यह program इसे जाँचता है।

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

कैसे काम करता है

  • word[::-1] slicing से string को उलटता है।
  • उलटी string original के बराबर हो तो palindrome है।

सारांश

  • Palindrome आगे और पीछे से एक जैसा पढ़ा जाता है, जैसे "madam" या 121। यह program इसे जाँचता है।
← Back to Python Tutorial
🔗

Share this topic with a friend

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

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

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

\n