Check sibling questions
Computer Science - Class 12
Chapter 14 - Functions in python

Write a Python program to reverse a string.

 

Answer:

def string_reverse (str1):

    rev_str= ""

    for i in str1:

        rev_str=i+rev_str

    return rev_str

 

str1=input( "Enter a string to reverse: " )

print("Reversed string is ",string_reverse(str1))

 

Question 6-Write a Python program to reverse a string - Teachoo.JPG

Are ads bothering you?


Transcript

Question 6Write a Python program to reverse a string. Defining a function to reverse a string For loop which iterates through each element of str1 Returning the reversed string Accepts a string as user input and assigns it to str1 output An empty string ‘rev_str’ is declared str1 is reversed by taking each element of str1 and assigning it to rev_str in reverse order

CA Maninder Singh's photo - Expert in Practical Accounts, Taxation and Efiling

Made by

CA Maninder Singh

CA Maninder Singh is a Chartered Accountant for the past 12 years. He also provides Accounts Tax GST Training in Delhi, Kerala and online.