- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Reverse a String without using Recursion
When it is required to reverse a string without using recursion technique, simple negative indexing can be used.
Indexing helps the values to access the elements at a specific index.
Example
Below is a demonstration for the same −
my_string = str(input("Enter a string that needs to be reversed: ")) print("The string after reversal is: ") print(my_string[::-1])
Output
Enter a string that needs to be reversed: Jane The string after reversal is: enaJ
Explanation
- The string input is taken by the user.
- This value is assigned to a variable.
- It is displayed on the console.
- It is negative indexed and displayed on the console.
Advertisements