top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Checking if a Word is Palindrome with Python

Updated: Sep 22, 2021

This is a simple python app that will tell you wether your text is a palindrome or not.


In this program, I have used the build-in reversed function to reverse the string.


Steps:

  1. First we define a function called ispalindrome()

  2. In this function, it first takes the input as an argument and lowercase the alphabets using pythons lower() method. Then it reverse the string using reversed() method.

  3. Then we compare the string with the reversed string and if they match it prints positive and negative otherwise.

Code:

def isPalindrome(s):
# Using predefined function to reverse to string print(s)
    str = s.lower()
    rev =''.join(reversed(str))
# Checking if both string are equal or not

    if (str == rev):
        print ("Yes. The word "+str+" is a Palindrome")

    else:
        print ("No. The word "+str+" is NOT a palindrome")

s = input()
ans = isPalindrome(s)

Output:

madam

Yes. The word madam is a palindrome.

 
 
 

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page