UrbanPro

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

How can I write a Python program to check if a string is a palindrome or not without reversing the original string?

Asked by Last Modified  

Follow 1
Answer

Please enter your answer

Enhance your skill set with quick courses in 'python', 'javascript' & 'sap ui5 / fiori / abap'

By reversing, the rhs will return the reverse of the string. >>> s='malayalam'>>> 'is a palindrome' if s==s else 'not a palindrome''is a palindrome'>>> >>> s=input('enter a string... ')enter a string... racecar>>> 'is a palindrome' if s==s else 'not a palindrome''is...
read more

By reversing, the rhs will return the reverse of the string.

>>> s='malayalam'
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'is a palindrome'
>>> 
>>> s=input('enter a string... ')
enter a string... racecar
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'is a palindrome'
>>> s=input('enter a string... ')
enter a string... a string
>>> 'is a palindrome' if s==s[::-1] else 'not a palindrome'
'not a palindrome'
>>>

_______________________________________________________________________________

Otherwise, you can check each character in the string read from the front against each character read from the back..

>>> s='malayalam'
>>> for i in range(len(s)):
             if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                    break
             else: None
else: 'is a palindrome'

'is a palindrome'
>>> s='rotor'
>>> for i in range(len(s)):
              if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                     break
              else: None
else: 'is a palindrome'

'is a palindrome'
>>> s='qwerty'
>>> for i in range(len(s)):
              if s[i]!=s[-(i+1)]:
                    'not a palindrome'
                     break
              else: None
else: 'is a palindrome

'not a palindrome'
>>>

read less
Comments

Related Questions

Which website should I learn Python from?
hey Abirami, I will recommend the following link- https://www.programiz.com/python-programming In case, if you require personal trainer I am online Python Tutor. Thanks, Rohit Maurya
Abirami
0 0
5
Hi, I'm BCA graduate, and I have seven years in the general insurance field now I want to change my profile and upgrade my knowledge. Will learning python help me with my growth in my career?
Hi, as far as my knowledge goes first, you should learn data processing tools or programs like MS Excel, Power Bi, or SQL then you should then take a leap into Python, which will make automating your work quite simple.
Supriya

which is beat among Rpa python Oracle In present situation , suggestion 

I would suggest you go for Python, as its one of the dominant language, you can do almost everything with Python. It's easy to learn and implement. I see lots of Job opportunity too.
K

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Why Python
Python can be used in any futuristics technology A= Analytics Data Science Artificial Intelligence(AI) Neural Network(NN) Natural Language Processing(NLP) Computer Vision(OpenCV) In Analytics...

Python : functional programming characteristics
Functions are first class (objects). That is, everything you can do with "data" can be done with functions themselves (such as passing a function to another function). Recursion is used as a primary...

Python Programming
Python is a widely used general-purpose, high-level programming language. This is an Open Source Software and its source code is available with a license in which the Copyright holder provides the rights...

Python Overview
Python is a high-level, interpreted, interactive and object-oriented scripting language. Python was developed by Gudo vanRossum in the late eighties and early nineties at the National Research Institute...

Write a python program to display dictonary details from list of dictonary
Print the Following: Print all dictonary in a seperate line. Name of all the products. Total quantity of all the products. Details of any product name when provided. Convert all the product name to upper case and print.
A

Ankit P.

0 0
0

Recommended Articles

Python is one of the most popular programming languages in the world. It is general-purpose, object oriented, high-level programming language used in a number of programming fields. Python is a great programming language to learn as it will introduce you to the world of programming. If you are from the technical background...

Read full article >

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Applications engineering is a hot trend in the current IT market.  An applications engineer is responsible for designing and application of technology products relating to various aspects of computing. To accomplish this, he/she has to work collaboratively with the company’s manufacturing, marketing, sales, and customer...

Read full article >

Looking for Python Training classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more