how to check if the string is pallindrome or not in python??
kisan 0 Newbie Poster
Recommended Answers
Jump to PostThere 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 PostBut 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
Jump to PostLet's hope this is not homework and the OP had a chance to learn something.
In a true palindrome test you also need to remove everything but the case adjusted letters.
"Madam in Eden I'm Adam" is a palindrome.
Jump to PostHere are a few things you can do with Python ...
s = "Madam, in Eden I'm Adam!" new = "" for c in s: if c.isalpha(): new += c print(new) # MadaminEdenImAdam # convert all characters to lower case new = new.lower() print(new) # madaminedenimadam # …
All 14 Replies
mn_kthompson 3 Junior Poster

masterofpuppets
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

masterofpuppets
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.