I have to check if the word or sentence is a palindrome using code, and I was able to check the words, but I am having trouble checking sentences like a palindrome. Here is my code, this is short, but I'm not sure how else to add it to check palindromes suggestion. I'm kind of a python beginner, and I've already looked at other people's code, and they are too complicated for me to really understand . Here is what I wrote:
def is_palindrome(s):
if s[::1] == s[::-1]:
return True
else:
return False
Here's an example of a sentence palindrome: "Red roses don't take risks, sir, in the order of nurses." (If you ignore spaces and special characters)
source
share