How to reverse string using append and reverse() in python?

Description

To reverse a given string in python3.

Append()

  

  Append is to join or add on to the end of something.

  

  The append() method takes a single  item and adds it  to the end of the list.

Reverse()

  

  It reverse the element in a list.

#get input from user
n=input(“Enter the string:”)

#declare an empty list
l=[]

#take input string in a loop
for i in n:

#append to the empty list
l.append(i)

#make reverse the list
l.reverse()

#join the ” in the list
a=”.join(l)
print(“The reversed version of string is\n”,a)

Leave Comment

Your email address will not be published. Required fields are marked *

clear formSubmit