How to reverse a string in python using for loop

Below is the code to reverse a string in python using for loop.

str = "GetHowStuff"
print("Original string is",str)
revstr = "" 
for i in str: 
    revstr = i + revstr
print("Reverse string (using for loop) is ",revstr)

Output

reverse a string in python using for loop output
Example code Output: Reverse string in Python

Alse see Calculate Python elapsed time in milliseconds

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

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