Skip to content
Home » Python code to check whether a word is Palindrome or not using functions

Python code to check whether a word is Palindrome or not using functions

Below is the python code to check whether a word is Palindrome or not using functions.

Palindrome: A word, phrase, or sequence that reads the same backwards as forwards

Example: madam

def Palin_Word(word):
    wd1=word
    if (wd1[::-1]==wd1):
        k=1
    else:
        k=0
    return k
# main program
wd=input("Enter a word:")
wd=wd.upper()
p=Palin_Word(wd)
if (p==1):
    print("Palindrome Word")
else:
    print("Not a Palindrome Word")

Output 1:

Enter a word:madam

Palindrome Word

Output 2:

Enter a word:python

Not a Palindrome Word