How to Check if a String is a Palindrome
A palindrome is a word or phrase that reads the same backward as forward. To check for a palindrome, you can reverse the string and compare it to the original.
Example: Checking for Palindrome
# Check if a string is a palindrome
word = "madam"
if word == word[::-1]:
print(f"{word} is a palindrome.")
else:
print(f"{word} is not a palindrome.")
Output
madam is a palindrome.
Explanation: The string is compared to its reversed version to check if it is a palindrome.