Example HTML page

A Python program to reverse a string without using recursion.

We can reverse a string by performing a slicing operation on it. The following example describes how to reverse a given string.

a=str(input("Enter a string: "))
print("Reverse string is: ")


Enter a string: Sudhakar

Reverse string is:


Here, String slicing is to be performed on the string “Sudhakar”. Whenever we perform slicing operation on string the default index position will be ‘0’ and it is ‘-1’ in the case of reverse string. Here we are reversing the string ‘Sudhakar’ so that ‘-1’ will be the index position. Therefore the output is “rakahduS”.

Example HTML page

Leave a Reply

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

Pin It on Pinterest