
- 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
Program to check a string is palindrome or not in Python
Suppose we have a string s; we have to check whether it is a palindrome or not. As we know a palindrome is when the word is the same forwards and backwards.
So, if the input is like s = "racecar", then the output will be True
To solve this, we will follow these steps −
- t := reverse of s
- if t is same as s, then
- return True
- otherwise,
- return False
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s): t=s[::-1] if t==s: return True else : return False ob = Solution() print(ob.solve("racecar"))
Input
"racecar"
Output
True
- Related Articles
- Python program to check if a string is palindrome or not
- Program to check string is palindrome or not with equivalent pairs in Python
- Program to check string is palindrome with lowercase characters or not in Python
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- C# program to check if a string is palindrome or not
- Program to check a number is palindrome or not without help of a string in Python
- Program to check two parts of a string are palindrome or not in Python
- How to Check Whether a String is Palindrome or Not using Python?
- Check if any anagram of a string is palindrome or not in Python
- Python program to check whether the string is Symmetrical or Palindrome
- C++ Program to Check Whether a Number is Palindrome or Not
- Program to check whether inorder sequence of a tree is palindrome or not in Python
- Program to check the string is repeating string or not in Python
- How to check a string is palindrome or not in Jshell in Java 9?
- Python Program to Check String is Palindrome using Stack

Advertisements