Python Program to Reverse a String Without using Recursion

This is a Python Program to reverse a string without using recursion.

Problem Description

The program takes a string and reverses the string without using recursion.

Problem Solution

1. Take a string from the user.
2. Use string slicing to reverse the string.
3. Print the reversed string.
4. Exit.

Program/Source Code

Here is source code of the Python Program to reverse a string without using recursion. The program output is also shown below.

a=str(input("Enter a string: "))
print("Reverse of the string is: ")
Program Explanation

1. User must enter a string.
2. By giving the increment value as -1, string slicing is used to reverse the list.
3. The reversed string is printed.

Runtime Test Cases
Case 1:
Enter a string: hello
Reverse of the string is: 
Case 2:
Enter a string: test
Reverse of the string is: 

Sanfoundry Global Education & Learning Series – Python Programs.

To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.