This is a quick tutorial on how you can reverse a string in python in just one line of code. There are numerous methods of reversing a string in python. But in this tutorial, I’ve just mentioned the one simplest method.
Reverse A String In Python Using String Splicing
The single line of code to Reverse a string is
reverseString = originalString[::-1]. The example code is given below.
aString = "Gurmeet Singh";
reverseString = aString[::-1]
The technique that we’re using here is known as String Splicing. It is the same technique that we can also use to find the different types of sub-strings of a string in Python.
Must-Read Guide. (You must read this guide as in it I’ve shared a few methods of finding substrings of a string and further how you can find the reverse of such strings)