Email: rakesh@xamnation.com         Phone/Whatsapp: +91 9988708161
interview questions

Check whether a string is palindrome

Hello,

Previously, we have seen how to find whether a number a palindrome or not in C++ (palindrome code in C++). In this article, we will see whether you can find a string(containing chars, numbers or special characters) and check whether it is a palindrome or not. We have shared python code to check palindrome sequence too.

What is Palindrome?

palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward. For example: Mom, 1221

Some more examples of palindrome are: Never odd or even, A man, a plan, a canal – Panama, Borrow or rob,A nut for a jar of tuna

Now, we will the implementation of code to check whether a string is palindrome or not in python.

 

 

def checkPalindrome(var):
	if(len(var.strip())==0):
		return "Invalid Entry"

	listVar = list(var.strip())
	i=0
	isPalindrome = "Palindrome found"
	while(i<len(listVar)):
		if(listVar[i]!=listVar[len(listVar)-i-1]):
			isPalindrome="No Palindrome"
			break
		i+=1

	return isPalindrome

print(checkPalindrome("abba"))

End note

In this article, we have showed you how to write a code to find palindrome in a string in Python. If you have any confusion regarding the code, please do comment in discussion thread below or send us email to info@xamnation.com. 

You can use our code in your website. Kindly do acknowledge us by linking our website or this page. 

About Xamnation

If you are interested, you can reach us at info@xamnation.com for more details. 

 

Leave a Comment

Your email address will not be published. Required fields are marked *