how to check if the string is pallindrome or not in python??
kisan 0 Newbie Poster
Recommended Answers
Jump to Post— mn_kthompson 3There is no built in function that I know of to check that.
On thing you might try doing is reversing the string and then comparing each element.
inString = 'racecar' reversestring = '' for i in range(0,len(inString)-1: reversestring.append(inString[i]Another way to do it would be …
Jump to Post— Member #562630there are a couple of posts regarding palindromes in the forum, have a look around.... but basically the algorithm is what mn_kthompson suggested :)
Jump to Post— abhi_elementx 1just compare the inString with reversestring using the == operator
Jump to Post— snippsat 661But how could we test if the given string is pallindrome or not. I need a syntax that returns true if the string is pallindrome otherwise false.
>>> def is_palindrome(s): ... return s.lower() == s[::-1].lower() ... >>> is_palindrome('test') False >>> is_palindrome('racecar') True >>> is_palindrome('RACECAR') True
All 14 Replies
mn_kthompson 3 Junior Poster
Member #562630
kisan 0 Newbie Poster
abhi_elementx 1 Junior Poster
snippsat 661 Master Poster
mn_kthompson commented: Very elegant solution to palindrome problem +2
abhi_elementx 1 Junior Poster
Member #562630
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
kisan 0 Newbie Poster
jlm699 320 Veteran Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
mn_kthompson 3 Junior Poster
mn_kthompson 3 Junior Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.