How to check for palindromes in python? [closed]

Can you write a method that checks whether a word or a phrase is a palindrome?

NOTE: Palindrome is a word which reads the same backwards. Eg = madam, racecar or phrases like “nurses run”.

Answer

You can do it like this:

def palindrome(s):
    
    s = s.replace(' ','') # This replaces all spaces ' ' with no space ''. (Fixes issues with strings that have spaces)
    return s == s[::-1]   # Check through slicing
palindrome('nurses run')