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:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.