Last active
October 1, 2018 09:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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