Write a python program to check whether given string is palindrome or not without using any inbuilt function to reverse the string



A palindrome is a string which is same read forward or backwards. Dad is a palindrome while Python is not.

In the program, we first accept the string to ‘string’. Since capital letters and small letters are perceived differently because of difference in ASCII codes, we convert the string to all lower for uniformity using inbuilt function ‘x.lower()’ where x is the string

In the above program, we have used the slice operator to reverese the string.The slice operator[n:m:p] returns the part of the string from nth to the (m-1)th character Setting p to -1 returns the reverse order of the slice of string you asked for. Since here we want the whole string, we use the shorthand [::-1]

Compare both the string and it’s reversal. If they are equal, then it’s a palindrome, otherwise not.



Do share your feedback in comments to help us adding more programs like this.

Checkout more Python Programs

Click here

Leave a Reply