
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to check if a string is palindrome or not
Given a string, our task is to check weather this string is palindrome or not.
Algorithm
Step1: Enter string as an input. Step2: Using string slicing we reverse the string and compare it back to the original string. Step3: Then display the result.
Example code
my_string=input("Enter string:") if(my_string==my_string[::-1]): print("The string is a palindrome") else: print("The string isn't a palindrome")
Output
Enter string:madam The string is a palindrome Enter string:python The string isn't a palindrome
- Related Articles
- C# program to check if a string is palindrome or not
- Program to check a string is palindrome or not in Python
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Check if any anagram of a string is palindrome or not in Python
- Program to check string is palindrome with lowercase characters or not in Python
- Program to check string is palindrome or not with equivalent pairs in Python
- How to Check Whether a String is Palindrome or Not using Python?
- Program to check a number is palindrome or not without help of a string in Python
- Python program to check if a given string is number Palindrome
- Program to check two parts of a string are palindrome or not in Python
- Python program to check if a given string is Keyword or not
- C Program to check if an Array is Palindrome or not
- Swift Program to check if an Array is Palindrome or not
- Write a C# program to check if a number is Palindrome or not
- Python program to check if the string is empty or not

Advertisements