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

SVM is applicable only for numeric data or can also be for textual data?
Any learning algorithm for that matter does not work Directly on text. It needs to be converted to a structured matrix before applying algorithms.The methods involve - 1. Extensive cleaning of the data...
Harsha
What are good books on advanced topics in Python?
Follow standard books which have ansi python. You can follow mc graw hill edition books or books written by python author or you can refer official documentation.
Vinodha
0 0
5
I am from ECE background, so I have no programming background so is it difficult to learn python n get a job as a fresher, and which combination best with python to learn? Currently, am in the networking domain, pls suggest me.
Good question and I teach a lot of students from non-CS background who want to shift their career to computer science. Even though you are from a non-CS background and have no programming experience before,...
Vijaykumar
0 0
7
I completed my graduation in 2017, now working as an HR Executive in a Consultancy. I want to move to IT Sector. Which course is best for me to learn and get success in life? Please Suggest me
Dear Kumar, My suggestion is to - become good in one programming language - preferably Java and one O/S preferably Linux. Be aware of Open Source systems. Try to identify the opportunities in your existing...
Kumar
Hi all, I'm looking for a tutor who can teach Data Structure, and also Object Oriented Programming w.r.t Python.
Hi, I'm a professional trainer and design consultant, and I do training on Python, AWS, C/C++. I do generally customize the training content and pace based on the student's absorbption level. I have trained...
Jigar

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

Ask a Question

Related Lessons

Python Demo
https://www.youtube.com/watch?v=8AEhpZ4lbOI

Using the random module: another program.
A Python module is just a file that contains reusable code like functions. If a program is going to use functions that are stored in another module, it needs to first import that module.The random module...

A Python Program to calculate Variance and Standard Deviation
Finding the variance and the standard deviation. Variance and Standard Deviation are related measures of dispersion that tell us more about a list of numbers,like are they...

Black in Python
When you are upturn in your career from beginner to experienced in programming world, your team will start looking at ‘how you are writing?’ Here the responsibility piling up. Okay,...

5 Reason to learn Python
Dynamically Typed You don’t have to declare a type when declaring a variable. It skips headaches of type casting JAVA:- int x = 1; x = (int)...

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