Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (50.2k points)

Can anyone tell me how to reverse the string in Python?

1 Answer

0 votes
by (108k points)

Python string library doesn't recommend the built-in ‘reverse()’ as done by other Python containers like lists. Hence, comprehending other methods to reverse strings can prove to be useful.

# Python code to reverse a string 

# using loop

def reverse(s):

  str = ""

  for i in s:

    str = i + str

  return str

s = "WelcometoIntellipaat"

print ("The original string  is : ",end="")

print (s)

print ("The reversed string(using loops) is : ",end="")

print (reverse(s))

If you are looking for an online course to learn Python, check out this Python Course by Intellipaat.

Related questions

0 votes
1 answer
asked Jan 2, 2021 in Python by laddulakshana (16.4k points)
0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
4 answers
0 votes
1 answer
asked Jul 13, 2020 in Python by ashely (50.2k points)

Browse Categories