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
🌐
EyeHunts
tutorial.eyehunts.com › home › how to reverse a string in python using for loop | example code
How to reverse a string in Python using for loop | Example code
January 13, 2023 - Note: Python string is not mutable, ... and store it in the variable. def reverse(text): rev_text = "" for char in text: rev_text = char + rev_text return rev_text print(reverse("ABC DEF"))...
Discussions

iterate over a string in reverse
https://docs.python.org/3/library/functions.html#reversed More on reddit.com
🌐 r/learnpython
7
1
February 7, 2023
How do I reverse a string in Python? - Stack Overflow
There is no built in reverse method for Python's str object. How can I reverse a string? More on stackoverflow.com
🌐 stackoverflow.com
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
🌐 r/Python
8
0
December 4, 2021
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
🌐 r/learnprogramming
15
12
September 21, 2023
🌐
Python Examples
pythonexamples.org › python-reverse-string
Python - Reverse String
# Given string x = "Hello World" # Reverse string using For loop x_reversed = '' for c in x: x_reversed = c + x_reversed # Print reversed string print(x_reversed) ... In this example, we use a Python While Loop statement, and during each iteration, we decrement the length.
🌐
GeeksforGeeks
geeksforgeeks.org › python › reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
For example: ... Python slicing supports step values. We can reverse the string by taking a step value of -1. ... 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
🌐
Tutorial Gateway
tutorialgateway.org › python-program-to-reverse-string
Python Program to Reverse a String
January 4, 2026 - For example, st1 = Hello. In the first iteration, st2 is H. In the second iteration, e is placed in the first position, and H pushes to the last position. st1 = input("Please enter your own: ") st2 = '' for i in st1: st2 = i + st2 print("After = ", st2) ...
🌐
Flexiple
flexiple.com › python › python-reverse-string
Reverse String In Python - Flexiple
March 18, 2024 - To reverse a string in Python using a loop, follow these steps. First, initialize an empty string that will hold the reversed string. Then, use a loop to iterate over the original string, adding each character to the beginning of the new string.
🌐
YouTube
youtube.com › watch
Python Tutorial : Reverse a String Using For Loop - YouTube
Learn how to reverse a string in Python using a for loop. This tutorial explains the step-by-step logic, including taking input, iterating through each chara...
Published   January 23, 2026
Find elsewhere
🌐
STechies
stechies.com › 5-different-ways-reverse-string-python
Reverse String in Python Using 5 Different Methods
... # Program to explain reverse ... = 'Stechies' # Print Original and Reverse string print('Original String: ', string) print('Reverse String: ', reverse_for(string))...
🌐
Quora
programmerprogramming.quora.com › How-to-Reverse-string-in-python-using-for-loop-See-2-different-methods-to-reverse-string-using-for-loop-python-pyt
How to Reverse string in python using for loop? See 2 different methods to reverse string using for loop. #python #pythontutorial #prog...
How to Reverse string in python using for loop? See 2 different methods to reverse string using for loop. #python #pythontutorial #programming #coding https://codingforbeginnersbinaryburst.quora.com/How-to-reverse-a-string-in-python-using-for-loop-1
🌐
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
🌐
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 - One way to reverse a string is to use a loop. We can iterate over the string from the end and add each character to a new string in reverse order. Here’s an example of reversing a string in Python ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-reverse-string
Python Reverse String - 5 Ways and the Best One | DigitalOcean
August 3, 2022 - $ python3.7 -m timeit --number 100000 --unit usec 'import string_reverse' 'string_reverse.reverse_slicing("ABç∂EF"*10)' 100000 loops, best of 5: 0.449 usec per loop $ python3.7 -m timeit --number 100000 --unit usec 'import string_reverse' 'string_reverse.reverse_list("ABç∂EF"*10)' 100000 loops, best of 5: 2.46 usec per loop $ python3.7 -m timeit --number 100000 --unit usec 'import string_reverse' 'string_reverse.reverse_join_reversed_iter("ABç∂EF"*10)' 100000 loops, best of 5: 2.49 usec per loop $ python3.7 -m timeit --number 100000 --unit usec 'import string_reverse' 'string_reverse.
🌐
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 - The string assigned to b has been reversed by the For loop. To see the reversed string b_reverse, use the print() function: ... For our example, “gnirts elpmaxe” would print in the terminal. ... Assign the string to a variable.
🌐
GUVI
guvi.in › blog › python › python reverse string: 7 effective ways with examples
Python Reverse String: 7 Effective Ways with Examples
January 8, 2026 - In this code, s1 starts as an empty string. Each iteration of the loop prepends the current character to s1, effectively building the string in reverse order. Must Explore: 16 Famous Tech Companies That Use Python
🌐
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 - After the loop completes iterations, we use the print() function to display both the original and reversed strings to the console. ... We've learned how to reverse a string in Python using explicit loops. In this section, we will discuss reversing strings in Python using a slicing operator.
🌐
Sololearn
sololearn.com › en › Discuss › 1525821 › how-to-reverse-a-string-in-python-using-for-loop
How to reverse a string in Python using for loop??
September 30, 2018 - Sololearn is the world's largest community of people learning to code. With over 25 programming courses, choose from thousands of topics to learn how to code, brush up your programming knowledge, upskill your technical ability, or stay informed about the latest trends.
🌐
Linode
linode.com › docs › guides › how-to-reverse-a-string-in-python
How to Reverse a String in Python | Linode Docs
May 13, 2022 - The code’s comments include more details on how this is achieved. example_string = "doom wolf" # Begin with an empty list. reversed_string_list = [] # Loop through the characters in the original string.
Top answer
1 of 14
3168

Using slicing:

>>> 'hello world'[::-1]
'dlrow olleh'

Slice notation takes the form [start:stop:step]. In this case, we omit the start and stop positions since we want the whole string. We also use step = -1, which means, "repeatedly step from right to left by 1 character".

2 of 14
329

What is the best way of implementing a reverse function for strings?

My own experience with this question is academic. However, if you're a pro looking for the quick answer, use a slice that steps by -1:

>>> 'a string'[::-1]
'gnirts a'

or more readably (but slower due to the method name lookups and the fact that join forms a list when given an iterator), str.join:

>>> ''.join(reversed('a string'))
'gnirts a'

or for readability and reusability, put the slice in a function

def reversed_string(a_string):
    return a_string[::-1]

and then:

>>> reversed_string('a_string')
'gnirts_a'

Longer explanation

If you're interested in the academic exposition, please keep reading.

There is no built-in reverse function in Python's str object.

Here is a couple of things about Python's strings you should know:

  1. In Python, strings are immutable. Changing a string does not modify the string. It creates a new one.

  2. Strings are sliceable. Slicing a string gives you a new string from one point in the string, backwards or forwards, to another point, by given increments. They take slice notation or a slice object in a subscript:

    string[subscript]
    

The subscript creates a slice by including a colon within the braces:

    string[start:stop:step]

To create a slice outside of the braces, you'll need to create a slice object:

    slice_obj = slice(start, stop, step)
    string[slice_obj]

A readable approach:

While ''.join(reversed('foo')) is readable, it requires calling a string method, str.join, on another called function, which can be rather relatively slow. Let's put this in a function - we'll come back to it:

def reverse_string_readable_answer(string):
    return ''.join(reversed(string))

Most performant approach:

Much faster is using a reverse slice:

'foo'[::-1]

But how can we make this more readable and understandable to someone less familiar with slices or the intent of the original author? Let's create a slice object outside of the subscript notation, give it a descriptive name, and pass it to the subscript notation.

start = stop = None
step = -1
reverse_slice = slice(start, stop, step)
'foo'[reverse_slice]

Implement as Function

To actually implement this as a function, I think it is semantically clear enough to simply use a descriptive name:

def reversed_string(a_string):
    return a_string[::-1]

And usage is simply:

reversed_string('foo')

What your teacher probably wants:

If you have an instructor, they probably want you to start with an empty string, and build up a new string from the old one. You can do this with pure syntax and literals using a while loop:

def reverse_a_string_slowly(a_string):
    new_string = ''
    index = len(a_string)
    while index:
        index -= 1                    # index = index - 1
        new_string += a_string[index] # new_string = new_string + character
    return new_string

This is theoretically bad because, remember, strings are immutable - so every time where it looks like you're appending a character onto your new_string, it's theoretically creating a new string every time! However, CPython knows how to optimize this in certain cases, of which this trivial case is one.

Best Practice

Theoretically better is to collect your substrings in a list, and join them later:

def reverse_a_string_more_slowly(a_string):
    new_strings = []
    index = len(a_string)
    while index:
        index -= 1                       
        new_strings.append(a_string[index])
    return ''.join(new_strings)

However, as we will see in the timings below for CPython, this actually takes longer, because CPython can optimize the string concatenation.

Timings

Here are the timings:

>>> a_string = 'amanaplanacanalpanama' * 10
>>> min(timeit.repeat(lambda: reverse_string_readable_answer(a_string)))
10.38789987564087
>>> min(timeit.repeat(lambda: reversed_string(a_string)))
0.6622700691223145
>>> min(timeit.repeat(lambda: reverse_a_string_slowly(a_string)))
25.756799936294556
>>> min(timeit.repeat(lambda: reverse_a_string_more_slowly(a_string)))
38.73570013046265

CPython optimizes string concatenation, whereas other implementations may not:

... do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b . This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-reverse-all-strings-in-string-list
Reverse All Strings in String List in Python - GeeksforGeeks
July 12, 2025 - It allows us to iterate over the list and apply a transformation to each element. ... Explanation: list comprehension iterates over each string in a and for each string s[::-1] reverses each string.