Write a program that reads a string and check whether it is a palindrome string or not.



Untitled 19.jpg


str=input( "Enter a string: " )

rev=str[:: -1 ]

if str==rev:

    print("Given string is a palindrome")


    print("Given string is not a palindrome")  



A string is a palindrome if it reads the same forwards and backwards.

A string can be reversed in python using the slice operation . If we ignore both the indexes and give step size as -1, the string is printed in reverse.

Now the entered string and the reversed string are compared to check whether the string is a palindrome or not.

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.