How to reverse string in Python ?

Author: neptune | 16th-May-2022 | views: 220

Different ways to reverse String in Python.

String is a widely used datatype in Python just like a list. In most of the interviews, a question was asked How to reverse a string in Python?
In this article, we will see a different way to reverse a String in Python.

1. Using Extended Slice Syntax:

Extended slice method takes three parameters [ start index: end index: increment ] just like the for a loop.


testString = 'Neptuneworld'




2.Using BuildIn method Reversed():

Reversed method returns a string reversed object which we can see that’s why we use to join and convert that object to a string using join.

Example :

testString = 'Neptuneworld'



Output :

3. Using for loop:

In this method, we iterate the string and add the element to the start of initialized empty string.


testString = 'Neptuneworld'

revString = str()

for ch in testString:

revString = ch + revString



4.Using Recursive Function:

def reverse(testString):

if len(testString) == 0:

return testString


return reverse(testString[1:]) + testString[0]


5.Using List  :

Using list also we can reverse the string as shown below.

testString = 'Neptuneworld'

revString = []

for i in range(len(testString)-1,-1,-1):



Thanks for Reading !!!

anonymous | Sept. 20, 2021, 11:20 p.m.


anonymous | Sept. 20, 2021, 11:04 p.m.

Also write about Java

Related Blogs
How to extract Speech from Video using Python?
Author: neptune | 30th-Apr-2022 | views: 1383
Simple and easy way to convert video into audio then text using Google Speech Recognition API...
How to download video from youtube using python module ?
Author: neptune | 24th-Apr-2022 | views: 809
We will let you know how you can easily download the Youtube high quality videos along with subtitle, thumbnail, description using python package..
Python 3.9 new amazing features ?
Author: neptune | 24th-Apr-2022 | views: 637
We are going to explore the newest features of Python 3.9 really amazing features here list of some features like Dict union, Type hinting etc. with examples...
Mostly asked Python Interview Questions - 2021.
Author: neptune | 22nd-Feb-2022 | views: 606
#Python #Interview
Python interview questions for freshers. These questions asked in 2021 Python interviews...
Python Built-in functions lambda, map, filter, reduce.
Author: neptune | 24th-Apr-2022 | views: 520
We are going to explore in deep some important Python build-in functions lambda, map, filter and reduce with examples...
Best Python package manager and package for virtual environment ?
Author: neptune | 15th-Apr-2022 | views: 463
#Python #Anaconda #Virtualenv #Pip
Which is the best package manager for python and Virtual environment management using Virtualenv and Anaconda...
Will, AI kills developers and programmers job ?
Author: neptune | 15th-Apr-2022 | views: 384
#Python #Machine learning #AI
GPT-3’s performance has convinced that Artificial intelligence is closer or at least AI-generated code is closer than we think. It generates imaginative, insightful, deep, and even excellent content...
Do you know Jupyter is now full-fledged IDE?
Author: neptune | 15th-Apr-2022 | views: 314
#Python #Jupyter
Jupyter is a widely used tool by Data scientists. So developers from institutions like Two Sigma, Bloomberg and convert it into IDE lets see..
What exactly you can do with Python?
Author: neptune | 15th-Apr-2022 | views: 286
Well, it's a tricky question to answer because there are lots of application of Python. But, I will tell you about 3 main applications of Python...
Introduction to Apache Spark
Author: neptune | 09th-May-2022 | views: 65
#Python #Apache Spark
Apache Spark is an open-source, distributed processing system that utilizes in-memory caching and optimized query execution for faster queries...
Datatypes in Python.
Author: neptune | 15th-May-2022 | views: 50
Python have different types of datatypes like Numbers, Strings, Lists, Tuples, Dictionary, Set, Frozenset, Bool, Mutable, and Immutable...
Core Python Syllabus for Interviews
Author: neptune | 14th-May-2022 | views: 41
#Python #Interview
STRING MANIPULATION : Introduction to Python String, Accessing Individual Elements, String Operators, String Slices, String Functions and Methods...
Deploy Django project on AWS with Apache2 and mod_wsgi module.
Author: neptune | 13th-May-2022 | views: 41
#Python #Django
In this blog I use the AWS Ubuntu 18.22 instance as Hosting platform and used Apache2 server with mod_wsgi for configurations. We create a django sample project then configure server...
View More