

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- Python program to check if a string is palindrome or not
- C# program to check if a string is palindrome or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- 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
- 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
- Program to check two parts of a string are palindrome or not in Python
- Check if any anagram of a string is palindrome or not in Python
- C++ Program to Check Whether a Number is Palindrome or Not
- Python program to check whether the string is Symmetrical or Palindrome
- 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
- Write a C# program to check if a number is Palindrome or not
- C Program to check if an Array is Palindrome or not
Advertisements