You are here: Home / Topics / Python Program to check if a string is palindrome or not

Python Program to check if a string is palindrome or not

Filed under: Python on 2023-09-17 22:02:50

#!/usr/bin/python
# -*- coding: utf-8 -*-
# Program to check if a string is palindrome or not

my_str = 'aibohphobia'

# make it suitable for caseless comparison

# 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.'

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.