Articles

program to check if a string is palindrome or not in python

program to check if a string is palindrome or not in python


In this python programming article, we are going to learn

  • program to check if a string is palindrome or not in python

Program to check if a string is palindrome or not in Python

The program to check whether a string is palindrome or not in python is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

word = input("Enter string: ").strip()

if word == word[::-1]:
    print("The string is palindrome!")
else:
    print("The string is not palindrome!")

The output of the program to check whether a string is palindrome or not in python is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter string: katak
The string is palindrome!

Few important tips about the program

1, A string is said to be palindrome only if the reverse of the string is same as the original one. Remember, palindrome check is case sensitive.

2. We have used negative indexing here, to reverse a word and compare it with the original one.

 

program to check if a string is palindrome or not in python snapshot:

program to check if a string is palindrome or not in python

This wraps up our session on program to check if a string is palindrome or not in python.


Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Apr 20,2022  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!