In this code snippet, we’ll show an example of a Python language function to check if a word is a palindrome (the same backwards).
Python language function to check if a word is a palindrome (the same backwards).
def is_palindrome(word: str) -> bool: """ Check if a given word is a palindrome. Args: word (str): The word to be checked. Returns: bool: True if the word is a palindrome, False otherwise. """ return word == word[::-1] print(is_palindrome("racecar")) print(is_palindrome("house"))
All code from this code snippet package can be downloaded here.
MIT Licensed Code – See License
Tags: python, words, palindrome