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

What is the difference between Python 2.x and Python 3.x?
Python 2.x and Python 3.x have several key differences: 1. **Print Statement**: In Python 2, `print` is a statement (`print "Hello"`), while in Python 3, it's a function (`print("Hello")`).2. **Integer...
Kartheek
0 0
5

I want to learn Python. but I cant decide which application to choose.I don't understand if I should be a Developer, testing or something else which is the future and which is more in demand.

Hello,You should first go for Python basics and practice some basic programming. Then advance your skillset.Python is quick to learn and use Pycharm as the IDE as it is widely used in the industry.
Srinu
How can I easily learn Python?
UrbanPro does not allow naming a website in answer so I have to write in this way. 'sololearnDOTcom/Course/python' is the website you can follow for easily learning python3. Its like playing a game over there.
Aditi
0 0
6
What are the most interesting Python books?
Some interesting Python books include: 1. **"Python Crash Course" by Eric Matthes** - A hands-on introduction to Python that covers basics and builds practical projects.2. **"Automate the Boring Stuff...
Arumugam
0 0
5

is there an best online exam simulator for PCAP 31-02 python exam ?

yes, this will work Python exam in cisco net grade, it 's free and help in practice and if you clear this exam, you will get 50% off PCAP 31-02 exam coupon on your registered email id.
Rajgun
0 0
5

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- 5 reasons to learn python
1. 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) x/2;...

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...

JAVA - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

Getting started with Python IDLE
Now that we have looked at some example programs, we would like to learn how to begin the actual process of writing a program in Python. There are a variety of ways to tell Python to execute the code we...

Top Programming Languages 2017: Every Beginner Should Learn
Every year a plethora of job opportunities are being created for skilled programmers. So if you are thinking of honing your coding skills it is really a bright idea. But with so many programming languages...

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