Write a Python Program to Check Whether a String is Palindrome or Not

Python Program to Check Whether a String is Palindrome or Not

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Check Whether a String is Palindrome or Not
Python Program to Check Whether a String is Palindrome or Not

Write a Python Program to Check Whether a String is Palindrome or Not

PROGRAM: Python Program to Check Whether a String is Palindrome or Not

/* Python Program to Check Whether a String is Palindrome or Not */

# Program to check if a string is palindrome or not

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(“The string is a palindrome.”)
else:
print(“The string is not a palindrome.”)

OUTPUT :-

The string is a palindrome.

Leave a Reply

Your email address will not be published. Required fields are marked *