Skip to content

Instantly share code, notes, and snippets.

@hargi12
Last active October 1, 2018 09:43
Show Gist options
  • Save hargi12/8586ae3978b1e7d95262ad43f4992692 to your computer and use it in GitHub Desktop.
Save hargi12/8586ae3978b1e7d95262ad43f4992692 to your computer and use it in GitHub Desktop.
A simple python script to check if a string is palindrome or not
# Program to check if a string
# is palindrome or not
# A palindrome is a word that reads the same backward and forward ie same number of characters, and meaning!
# change this value for a different output
my_str = 'aIbohPhoBiA'
# make it suitable for caseless comparison
my_str = my_str.casefold()
# reverse the string
rev_str = reversed(my_str)
# check if the string is equal to its reverse
if list(my_str) == list(rev_str):
print("It is palindrome")
else:
print("It is not palindrome")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment