python-tutorialsmade

Reverse a string without using build in method [::-1] in Python

 

If you are new to Python and you don’t know how to reverse a string in Python, here is a sample script using default reverse method [::-1]:

The output of the above program:

Enter a String
superman
Reverse is: namrepus

So basically using [::-1], it is possible to reverse a string, but in interviews, sometimes to test your logical programming skill they may ask you to write a program to reverse a string without using the default reverse method.

The solution for the above question is to write a custom reverse() function in Python.

Here is the solution:

The above code is well commented, read them to understand.
Are you a Python web developer?, you may need this script!!

This is the Python web script version of reversing a string without using default method:

The same custom reverse() function is used in the Python web script also, read the comments to understand the other features in the above script such is submitting a form, storing the form value in a variable, calling a function etc.,

And finally the demo of the web script,

demo

 

Related Posts

Leave a Reply