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?
A 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"))
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 email@example.com.
You can use our code in your website. Kindly do acknowledge us by linking our website or this page.
- We are offering online courses in technical skills and interview preparation. Do visit Xamnation courses to check complete list of our courses. We are offering live classes, online material and interview series for cracking job interviews. Our famous courses are :
- Online Python Course
- Online Java Course
- Online Machine Learning Course
- Online Data Structure Course
If you are interested, you can reach us at firstname.lastname@example.org for more details.