🌐
dbader.org
dbader.org › blog › python-reverse-string
How to Reverse a String in Python – dbader.org
January 9, 2018 - An overview of the three main ways to reverse a Python string: “slicing”, reverse iteration, and the classic in-place reversal algorithm. Also includes performance benchmarks.
🌐
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.
Discussions

What is the most efficient way to reverse a string in Python? - Stack Overflow
I'm looking for the most efficient method to reverse a string in Python. While there are several approaches to accomplish this task, I want to know which technique provides the best performance in ... More on stackoverflow.com
🌐 stackoverflow.com
Fastest way to reverse a string - and it's not extended string splicing?
I was told there's a faster method with some optimisations possible. If reversing strings is a bottleneck needing optimization, then your codebase might have bigger issues. More on reddit.com
🌐 r/learnpython
70
245
August 12, 2020
Algorithm complexity with strings and slices

The python page on time-complexity shows that slicing lists has a time-complexity of O(k), where "k" is the length of the slice. That's for lists, not strings, but the complexity can't be O(1) for strings since the slicing must handle more characters as the size is increased. At a guess, the complexity of slicing strings would also be O(k). We can write a little bit of code to test that guess:

import time

StartSize = 2097152

size = StartSize
for _ in range(10):
    # create string of size "size"
    s = '*' * size

    # now time reverse slice
    start = time.time()
    r = s[::-1]
    delta = time.time() - start

    print(f'Size {size:9d}, time={delta:.3f}')

    # double size of the string
    size *= 2

This uses a simple method of timing. Other tools exist, but this is simple. When run I get:

$ python3 test.py
Size   2097152, time=0.006
Size   4194304, time=0.013
Size   8388608, time=0.024
Size  16777216, time=0.050
Size  33554432, time=0.098
Size  67108864, time=0.190
Size 134217728, time=0.401
Size 268435456, time=0.808
Size 536870912, time=1.610
Size 1073741824, time=3.192

which shows the time doubles when doubling the size of the string for each reverse slice. So O(n) (k == n for whole-string slicing).

Edit: spelling.

More on reddit.com
🌐 r/learnpython
4
3
December 1, 2019
What is the time complexity of reversing a string?
It should be simply O(n) where n is the length of string. If you think of a string as an array, you simply swap characters between left and right ends until they cross over the mid-point — which means O(n/2) and simplified to O(n). More on reddit.com
🌐 r/algorithms
13
10
October 23, 2020
🌐
Medium
medium.com › better-programming › benchmarking-the-best-way-to-reverse-a-string-in-python-9c73d87b1b1a
Benchmarking the Best Way to Reverse a String in Python | by Nick Gibbon | Better Programming
September 16, 2019 - Slicing is the most efficient way to reverse a string in python. Reverse to swap inline and reversed for a copy perform well and are clearer. String concatenation, as implemented in the slower algorithms, should be avoided.
🌐
Real Python
realpython.com › reverse-string-python
Reverse Strings in Python: reversed(), Slicing, and More – Real Python
July 31, 2023 - Python provides two straightforward ways to reverse strings. Since strings are sequences, they’re indexable, sliceable, and iterable. These features allow you to use slicing to directly generate a copy of a given string in reverse order.
🌐
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 - Learn how to reverse a string in Python using loops, slicing, recursion, stack, and more. Explore challenges and multiple methods.
🌐
Real Python
realpython.com › lessons › python-reverse-string-custom-algorithm
Reversing a String Using a Custom Algorithm (Video) – Real Python
For example, let’s say you want to reverse the string "HELLO". During the first iteration, the "H" and "O" would be swapped, as the left pointer is equal to 0, and the right pointer is equal to 4. During the second iteration, the left pointer has now been incremented to 1, with the right having been decremented to 3. Therefore, the "E" and the "L" would be swapped. During the third and final iteration, the left and right pointers would both equal 2, and therefore the algorithm would exit, returning the string, "OLLEH".
Published   August 1, 2023
🌐
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 - Here's a Python code for the same: ... bnVtYmVyID0gMTIzNDUNCnJldmVyc2VkX251bWJlciA9IGludChzdHIobnVtYmVyKVs6Oi0xXSkNCg0KcHJpbnQocmV2ZXJzZWRfbnVtYmVyKQ== ... In Python, the fastest algorithm to reverse a string is using slicing with [::-1]. This ...
🌐
GeeksforGeeks
geeksforgeeks.org › reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
Let's explore the other different methods to reverse the string: ... Python provides a built-in function called reversed(), which can be used to reverse the characters in a string.
Published   November 21, 2024
Find elsewhere
🌐
Educative
educative.io › home › courses › data structures and algorithms in python › reverse string
Reverse a String Using Stack in Python for LIFO Operations
Explore how to reverse a string using a stack in Python by pushing each character onto the stack and popping them off to get the reversed result. Understand the algorithm and implement it to strengthen your knowledge of stack operations and string manipulation.
🌐
Educative
educative.io › answers › how-do-you-reverse-a-string-in-python
How do you reverse a string in Python?
This technique reverses a string using reverse iteration with the reversed() built-in function to cycle through the elements in the string in reverse order and then use .join() method to merge all of the characters resulting from the reversed ...
🌐
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 example, the reverse_string function takes an input string, applies the reversed() function to create an iterator, and then uses "".join() to form the reversed string. This method is straightforward and leverages Python’s powerful built-in functions to perform the task efficiently.
🌐
LeetCode
leetcode.com › problems › reverse-string
Reverse String - LeetCode
The input string is given as an array of characters s. You must do this by modifying the input array in-place [https://en.wikipedia.org/wiki/In-place_algorithm] with O(1) extra memory.
🌐
Stack Abuse
stackabuse.com › how-to-reverse-string-in-python
How to Reverse String in Python
May 24, 2022 - In this short guide, learn how to reverse a string in Python, with practical code examples and best practices - using the slice notation with a negative step, a for loop, a while loop, join() and reversed().
🌐
Reddit
reddit.com › r/learnpython › fastest way to reverse a string - and it's not extended string splicing?
r/learnpython on Reddit: Fastest way to reverse a string - and it's not extended string splicing?
August 12, 2020 -

An interview question I got was the following:

Write a function that reversed a string s. Speed is important.

I gave them back a 1 liner, returning

s[::-1]

I was told there's a faster method with some optimisations possible.

Some assumptions:

  • Reasonable real world memory limitations.

  • Input string is a valid string.

  • No information on distribution or makeup of strings

How should I have done it?

🌐
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.
🌐
ScholarHat
scholarhat.com › home
How to Reverse a String in Python
September 11, 2025 - Be one with our Free Python Online Course—start your journey now! Using Slicing ([::-1]): Slicing is the most efficient method to reverse a string in Python.
🌐
Interviewing.io
interviewing.io › questions › reverse-string
How to Reverse a String [Interview Question + Solution]
September 13, 2018 - Space Complexity: O(n). We are using a character array to store the characters of the string. So the space complexity is O(n). If the input to the function is a character array itself or the language supports string mutability, then the space complexity would be O(1), because the algorithm does an in-place reversal of the character array / string.