This is a Python Program to check if a string is a palindrome or not.
The program takes a string and checks if a string is a palindrome or not.
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.
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:") if(string==string[::-1]): print("The string is a palindrome") else: print("The string isn't a palindrome")
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.
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.
- Check Python Books
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Python Internship
- Apply for Programming Internship