
- 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
How to Check Whether a String is Palindrome or Not using Python?
Use reveresed() function from Python's standard library. It returns reversed object which can be converted in a list object
>>> str1='malayalam' >>> l1=list(reversed(str1)) >>> l1 ['m', 'a', 'l', 'a', 'y', 'a', 'l', 'a', 'm']
Join all characters in a list using join() method
>>> str2=''.join(str(x) for x in l1)
Compare str1 and str2. If they are equal the original string is a palindrome
>>> if str1==str2: print ('palindrome') else: print ('not palindrome')
- Related Articles
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Python 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 the string is Symmetrical or Palindrome
- C++ Program to Check Whether a Number is Palindrome or Not
- How to check whether a number is prime or not using Python?
- Program to check whether inorder sequence of a tree is palindrome or not in Python
- C# program to check if a string is palindrome or not
- Python program to check whether a given string is Heterogram or not
- Check if any anagram of a string is palindrome or not in Python
- Check whether a string is valid JSON or not in Python
- 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 a string is palindrome or not in Jshell in Java 9?
- Program to check a number is palindrome or not without help of a string in Python

Advertisements