Share

How to reverse string in Python ?

Author: neptune | 19th-Sep-2021 | views: 43
#Python

Different ways to reverse String in Python.

Using Extended Slice Syntax:

testString = 'Neptuneworld'

testString=testString[::-1]

print(testString)

Using BuildIn method Reversed():

testString = 'Neptuneworld'

testString=''.join(reversed(testString))

print(testString)


Using for loop:

testString = 'Neptuneworld'

revString = str()

for ch in testString:

revString = ch + revString

print(revString)

Using Recursive Function:

def reverse(testString):

if len(testString) == 0:

return testString

else:

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

print(reverse("NeptuneWorld"))

Using List  :

testString = 'Neptuneworld'

revString = []

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

revString.append(testString[i])


print(''.join(revString))




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

✌️


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

Also write about Java



Related Blogs
Python 3.9 new amazing features ?
Author: neptune | 25th-May-2021 | views: 213
#Python
Some of the best new feature of Python 3.9 like Dict union, Type hinting with examples..
Python Built-in functions lambda, map, filter, reduce.
Author: neptune | 26th-May-2021 | views: 198
#Python
We are going to explore in deep some important Python build-in functions lambda,map,filter and reduce with examples..
How to extract Speech from Video using Python?
Author: neptune | 25th-May-2021 | views: 190
#Python
Simple and easy way to convert video into audio then text using Google Speech Recognition API..
Best Python package manager and package for virtual environment ?
Author: neptune | 29th-May-2021 | views: 184
#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 | 05th-Jun-2021 | views: 163
#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...
What exactly you can do with Python?
Author: neptune | 29th-May-2021 | views: 122
#Python
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...
How to download video from youtube using python module ?
Author: neptune | 26th-May-2021 | views: 120
#Python
We will let you know how you can easily download the Youtube high quality videos along with subtitle, thumbnail, description using python package..
Do you know Jupyter is now full-fledged IDE?
Author: neptune | 25th-May-2021 | views: 111
#Python #Jupyter
Jupyter is a widely used tool by Data scientists. So developers from institutions like Two Sigma, Bloomberg and fast.ai convert it into IDE lets see..
Mostly asked Python Interview Questions - 2021.
Author: neptune | 30th-Sep-2021 | views: 93
#Python #Interview
Python interview questions for freshers. These questions asked in 2021 Python interviews...
View More