String Palindrome Program in Python


This is a Python Program to check if a string is a palindrome or not.

Problem Description

The program takes a string and checks if a string is a palindrome or not.

Problem Solution

1. Take a string from the user and store it in a variable.
2. Reverse the string using string slicing and compare it back to the original string.
3. Print the final result
4. Exit.

Program/Source Code

Here is source code of the Python Program to check if a string is a palindrome or not. The program output is also shown below.

string=raw_input("Enter string:")
      print("The string is a palindrome")
      print("The string isn't a palindrome")
Program Explanation

1. User must enter a string and store it in a variable.
2. The string is reversed using string slicing and it is compared back to the non-reversed string.
3. If they both are equal, the strings are palindromes.
4. If they aren’t equal, the strings aren’t palindromes.
6. The final result is printed.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
Runtime Test Cases
Case 1:
Enter string:malayalam
The string is a palindrome
Case 2:
Enter string:hello
The string isn't a palindrome

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.