In python programming whether a text in a palindrome will ignore punctuation, spaces and cases or will it consider it??? i need a python program to prove "Rise to vote, sir." as a palindrome.. can anyone help me???
Strings are actually arrays of characters. Therefore, you just check if the 0th character is equal to the len(string) - 1th character. You can just recurse until the beginning index is greater than or equal to the ending index.
Each character, including punctuation, contained in the string array is actually stored as a unique uni-code value integer value. It is your program that determines how these values are interpreted, rather than Python.
To answer your question, yes, python will consider punctuation to be a character. An example of what you are looking for is: Forward = "Rise to vote, sir" Backward = Forward[::-1] if lower(Forward) == lower(Backward) print "Palindrome!" Of course, this will fail as the comma will mess up the comparison. If your assignment mandates that punctuation should not affect whether something is a palindrome, you can simply walk through the string first and only copy alpha characters to a new string then run the comparison on that.
Join our real-time social learning platform and learn together with your friends!