You can also do it with recursion:

def reverse(text):
    if len(text) <= 1:
        return text

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

And a simple example for the string hello:

   reverse(hello)
 = reverse(ello) + h           # The recursive step
 = reverse(llo) + e + h
 = reverse(lo) + l + e + h
 = reverse(o) + l + l + e + h  # Base case
 = o + l + l + e + h
 = olleh
Answer from Blender on Stack Overflow
🌐
CodeSpeedy
codespeedy.com › home › reverse string without using function in python
Reverse string in Python without using function- CodeSpeedy
March 16, 2022 - Since we are not using any function, we will need an empty string so that we can concatenate it with each letter of the string using a for loop which we will be discussing in the next step.
Discussions

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
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
People also ask

Q1. What is the easiest way to reverse a string in Python?
The easiest way is by slicing the string backwards using [::-1]. It is quick and simple for beginners.
🌐
intellipaat.com
intellipaat.com › home › blog › how to reverse a string in python
How to Reverse a String in Python: 7 Methods to Reverse String
Q4. Can recursion be used for reversing a String in Python?
Yes, recursion works by breaking the string into smaller parts and moving the first letter to the end at each step. This continues until the whole string is reversed.
🌐
intellipaat.com
intellipaat.com › home › blog › how to reverse a string in python
How to Reverse a String in Python: 7 Methods to Reverse String
Q2. Can a loop be used to reverse a string?
Yes, a loop can take each letter and add it in front to make the string reversed step-by-step.
🌐
intellipaat.com
intellipaat.com › home › blog › how to reverse a string in python
How to Reverse a String in Python: 7 Methods to Reverse 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.

🌐
W3Schools
w3schools.com › python › python_howto_reverse_string.asp
How to reverse a String in Python
There is no built-in function to reverse a String in Python. The fastest (and easiest?) way is to use a slice that steps backwards, -1.
🌐
w3tutorials
w3tutorials.net › blog › reverse-a-string-without-using-reversed-or-1
How to Reverse a String in Python Without Using reversed() or [::-1] — w3tutorials.net
def reverse_string_while_loop(s): reversed_str = "" index = len(s) - 1 # Start at the last character while index >= 0: reversed_str += s[index] index -= 1 # Move to the previous character return reversed_str # Test the function original_string = "python" reversed_string = reverse_string_while_loop(original_string) print(f"Original: {original_string}, Reversed: {reversed_string}") # Output: Original: python, Reversed: nohtyp
Find elsewhere
🌐
Hostman
hostman.com › tutorials › how-to-reverse-a-string-in-python
How to Reverse a String in Python | Step-by-Step Guide
If we want to reverse a string using the basic programming structures without utilizing a built-in function, we can achieve this with traditional Python for loop. We can use the for loop to iterate over our string in the opposite direction from the last index to the first index.
🌐
Quora
quora.com › How-do-I-reverse-a-string-in-Python-without-slicing-and-indexing
How to reverse a string in Python without slicing and indexing - Quora
Answer (1 of 4): To reverse a string without using slicing and indexing, there can be two possible approaches: 1. for loop: Using for loop, extract the letters/characters of the string one by one and add them to another empty string in reversed order. Output of the above code 2. reversed metho...
🌐
GeeksforGeeks
geeksforgeeks.org › python › reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
Reverse the string by iterating over its indices in reverse order using range(). The list comprehension collects characters from last to first, and join() combines them into the final reversed string.
Published   March 3, 2026
🌐
Javatpoint
javatpoint.com › how-to-reverse-a-string-in-python
How to reverse a string in Python - Javatpoint
How to reverse a string in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, basics, data types, operators, etc.
🌐
Quora
quora.com › Is-there-a-way-to-reverse-a-string-in-Python-without-using-loops-or-other-methods-that-are-inefficient
Is there a way to reverse a string in Python without using loops or other methods that are inefficient? - Quora
Answer: Efficiency isn’t likely to come into play when reversing a string. Also, there is simply no need to use a loop to reverse a string in Python. Additionally, since strings are immutable, while we say “reverse a string”, we should be clear that what we are doing is “generating ...
🌐
24HourAnswers
24houranswers.com › technical-tutoring-tips › How-to-Reverse-a-String-in-Python
How to Reverse a String in Python
October 13, 2021 - In Python, strings are iterable and there is no included function to reverse a string. One rationale for excluding a string.reverse() method is to give Python developers an incentive to leverage the power of this special circumstance.
🌐
Linuxize
linuxize.com › home › python › how to reverse a string in python
How to Reverse a String in Python | Linuxize
August 1, 2021 - Python doesn’t have any built-in functions to reverse the string, but we can use other methodsto reverse the string.
🌐
Python Engineer
python-engineer.com › posts › reverse-string-python
How to reverse a String in Python - Python Engineer
There is no built-in string.reverse() function. However, there is another easy solution. ... The recommended way is to use slicing.
🌐
Educative
educative.io › answers › how-do-you-reverse-a-string-in-python
How do you reverse a string in Python?
In Python, strings are ordered sequences of character data. There is no built-in method to reverse a string.
🌐
GUVI
guvi.in › blog › python › python reverse string: 7 effective ways with examples
Python Reverse String: 7 Effective Ways with Examples
January 8, 2026 - This behavior minimizes memory ... element from a list in Python? 4 Methods · Here’s a practical example of using the reversed() Function to reverse a string in Python:...
🌐
ReqBin
reqbin.com › code › python › hcwbjlmi › python-reverse-string-example
How do I reverse a string in Python?
The easiest and fastest way to reverse a string in Python is to use the slice operator [start:stop:step]. When you pass a step of -1 and omit the start and end values, the slice operator reverses the string.
🌐
Intellipaat
intellipaat.com › home › blog › how to reverse a string in python
How to Reverse a String in Python: 7 Methods to Reverse String
September 2, 2025 - To reverse a string without built-in functions, start by creating an empty string to hold the result. Use a loop, such as for or while, to go through the original string from the end to the beginning.