Python string is not mutable, so you can not use the del statement to remove characters in place. However you can build up a new string while looping through the original one:
def reverse(text):
rev_text = ""
for char in text:
rev_text = char + rev_text
return rev_text
reverse("hello")
# 'olleh'
Answer from akuiper on Stack Overflow Top answer 1 of 4
7
Python string is not mutable, so you can not use the del statement to remove characters in place. However you can build up a new string while looping through the original one:
def reverse(text):
rev_text = ""
for char in text:
rev_text = char + rev_text
return rev_text
reverse("hello")
# 'olleh'
2 of 4
6
The problem is that you can't use del on a string in python.
However this code works without del and will hopefully do the trick:
def reverse(text):
a = ""
for i in range(1, len(text) + 1):
a += text[len(text) - i]
return a
print(reverse("Hello World!")) # prints: !dlroW olleH
GeeksforGeeks
geeksforgeeks.org › python › reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
Python provides a built-in function called reversed() which can be used to reverse the characters in a string. ... If we need more control over the reversal process then we can use a for loop to reverse the string.
Published March 3, 2026
7 proven methods to reverse the python string in 2021
"".join(sorted(a, reverse=True)) will not reverse a string. >>> a = "hello world" >>> "".join(sorted(a, reverse=True)) 'wroolllhed ' There's a deeper problem with articles like this, though. Reversing a string is a trivial task (i.e., it's something for a beginner to learn). Giving seven different methods with no explanation on if one is better than another is not good teaching, especially when some don't even work and others are pointlessly verbose. More on reddit.com
iterate over a string in reverse
https://docs.python.org/3/library/functions.html#reversed More on reddit.com
Why does [::1] reverse a string in Python?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
Videos
02:41
Python Tutorial : Reverse a String Using For Loop - YouTube
00:44
#Python Reverse a String Using For Loop. - YouTube
04:20
Python Interview Prep | Alternate Ways to Reverse a String using ...
03:47
How to Reverse a String in Python | Three Ways to Reverse a String ...
11:29
Python Program to Reverse a String using for loop - Hindi #18 - ...
DigitalOcean
digitalocean.com › community › tutorials › python-reverse-string
Python Reverse String - 5 Ways and the Best One | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
wikiHow
wikihow.tech › computers and electronics › software › programming › python › 6 ways to reverse a string in python: easy guide + examples
6 Ways to Reverse a String in Python: Easy Guide + Examples
March 20, 2023 - Trying to reverse a string in Python? There are several easy ways to do so! You can use the slice function to reverse the string in 1 line of code. Alternatively, use a For loop or the reversed() function for additional flexibility in the reversal process. You can also use the join() function ...
Python Examples
pythonexamples.org › python-reverse-string
Python - Reverse String
Python Program to Reverse String - In this tutorial, we shall learn how to reverse a string using 1. String Slicing 2. For Loop 3. While Loop and 4. List.reverse(). Examples for each of the processes is given.
Real Python
realpython.com › reverse-string-python
Reverse Strings in Python: reversed(), Slicing, and More – Real Python
July 31, 2023 - So far, you’ve learned about core Python tools and techniques to reverse strings quickly. Most of the time, they’ll be your way to go. However, you might need to reverse a string by hand at some point in your coding adventure. In this section, you’ll learn how to reverse strings using explicit loops and recursion. The final technique uses a functional ...
Unstop
unstop.com › home › blog › how to reverse a string in python in 10 ways! (code)
How To Reverse A String In Python In 10 Ways! (Code)
December 21, 2023 - You can reverse a string in Python using a for loop with the following steps- Initialize an empty string to store the reversed version. Initiate a loop for iteration on string characters, i.e., characters of the initial string in reverse order using the range() function and len() function.
Python Guides
pythonguides.com › python-program-to-reverse-a-string
How To Reverse A String In Python?
January 12, 2026 - Master Python string reversal with my expert guide. Learn slicing, join methods, and recursion with real-world USA examples. Perfect for Python developers.
YouTube
youtube.com › watch
Three Ways to Reverse a String in Python TUTORIAL (using For Loops, reversed(), and Slice Notation) - YouTube
Python tutorial on 3 ways to reverse a string.This is a common python interview question. 📖 You can check out the Udemy course (Python Built-in Functions) h...
Published August 5, 2019
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › how to reverse a string in python
How to Reverse a String in Python - Shiksha Online
March 3, 2023 - Let’s understand how to reverse a string in Python using various methods: #Define a function def rev_func(string): # Declare a string variable revstr = '' #Iterate string with for loop for x in string: # Appending chars in reverse order revstr = x + revstr return revstr string = str(input()) ...
Analytics Vidhya
analyticsvidhya.com › home › 5 ways to reverse a string in python
How to Reverse a String in Python in 5 Ways | Reverse Function
February 5, 2025 - In this case, it is important to ensure the function is robust and handles all edge cases correctly. Overall, while reversing a string in Python may seem like a simple task, there are several challenges that developers need to consider. By understanding these challenges and choosing the appropriate approach, you can efficiently reverse the strings in your Python programs. Several ways to reverse an input string in Python include loops...
Scaler
scaler.com › home › topics › string reverse in python
Reverse String in Python - Scaler Topics
April 8, 2022 - When we use strings in our python code, we can come across several conditions where we have to reverse the string, but we don't have any inbuilt function for reversing the string. In that case, we can use many approaches that can be useful in reversing the string, like using extended slice syntax, looping...