What is a Palindrome ?

A palindrome is a symmetrical word, (i.e. it reads the same backward as forwards).

For example:

  • racecar

  • madam

  • radar

Now that we know what is a palindrome we can write a code in Python for the same.

def palindrome(word):
  if len(word)<=1:
    return True
  if word[0] != word[-1]:
    return False
  return palindrome(word[1:-1])

print(palindrome("racecar"))

There is also an another solution for this:

def isPali(inp):
  if inp[0 : len(inp)] == inp[ : : -1]:
    print("\nThe inputed String is a Palindrome")
  else:
    print("\nThe Inputed String is not a Palindrome")

ch = 'y'
while ch == 'y' or ch == 'Y':
  print("\033[31m" + "\n✅ Palindrome Checker ✅")
  inpu = input("\033[0m" + "\nEnter the String to Be Checked: ").lower()
  isPali(inpu)
  ch = input("Do You Want To Continue: ")

Feel free to try both and express your views...

Today is 59 / 100 days in my Python Journey, Join Here to take up the Journey With me: https://join.replit.com/python

See You tomorrow...

0
Subscribe to my newsletter

Read articles from Ajay Vikhram S M directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ajay Vikhram S M
Ajay Vikhram S M

I am a Tech enthusiast interested to learn new things from everyone and post my learning in public.