Skip to content

Instantly share code, notes, and snippets.

@nikolaysm
Created August 29, 2024 23:27
Show Gist options
  • Save nikolaysm/7582d09c5610d1c62374a77b52390c7c to your computer and use it in GitHub Desktop.
Save nikolaysm/7582d09c5610d1c62374a77b52390c7c to your computer and use it in GitHub Desktop.
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Function to test if a word is a palindrome
def is_palindrome(word):
"""
Check if a word is a palindrome.
Args:
word (str): The word to check.
Returns:
bool: True if the word is a palindrome, otherwise False.
"""
# Convert the word to lowercase to make the check case-insensitive.
normalized_word = word.lower()
# Check if the word reads the same forward and backward.
return normalized_word == normalized_word[::-1]
# Usage
print(is_palindrome("Radar")) # Should return True
print(is_palindrome("Python")) # Should return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment