def reverseStr(s):
return ' '.join([x[::-1] for x in s.split(' ')])
Answer from saarrrr on Stack OverflowGeeksforGeeks
geeksforgeeks.org โบ python โบ reverse-words-given-string-python
Reverse Words in a Given String in Python - GeeksforGeeks
October 27, 2025 - This method manually iterates through the list of words in reverse order, building the reversed string step by step. It is helpful when you want to control the process explicitly. ... s = "Python is fun" words = s.split() res = "" for word in reversed(words): res += word + " " res = res.strip() print(res)
Reddit
reddit.com โบ r/learnpython โบ how to do reverse word in python?
r/learnpython on Reddit: How to do reverse word in python?
October 4, 2017 -
I can do this: hello world dlrow olleh
But the thing I need is: hello world olleh dlrow
Thanks a lot!
Top answer 1 of 3
3
You can split your string into words with the split function, it splits on whitespace like so: "hello world".split() And then you can reverse the individual words.
2 of 3
3
How did you go about achieving the first example? I suspect you did it through 'hello world'[::-1]? What you could do is simply to reverse each word separately, and then concatenate them together again: words = 'my string goes here'.split(' ') reversed = [] for word in words: reversed.append(word[::-1]) print(' '.join(reversed)) or, shorter: words = 'my string goes here'.split(' ') print(' '.join([word[::-1] for word in words]))
Method for reversing strings - Ideas - Discussions on Python.org
I would like to add a .reverse() method for strings. I think most modern languages have something like that and [::-1] is a bit archaic with little charm. There may be other methods like splitting the string, reversing the resulting list, and then joining it back, but thatโs a bit of work! More on discuss.python.org
How to do reverse word in python?
You can split your string into words with the split function, it splits on whitespace like so: "hello world".split() And then you can reverse the individual words. More on reddit.com
Today's daily challenge "Reverse words in a string" - Python Solution
return " ".join(filter(lambda x:len(x)!=0,s.split(" ")[::-1])) More on reddit.com
In my opinion this is the simplest and modern way to reverse a string. What do you think? Do you know easier ways?
Esoteric fun fact: though the code in the video is the cleanest, itโs not the most performant. According to jsbench.me, this is 46% faster: let reversed = ''; for (let i = string.length -1; i >= 0; i--){ reversed = reversed + string.charAt(i); } Itโs not as pretty, but the reason this is more performant is that [...str].reverse.join("") has to iterate through the string at least 3 times (one for the split, then again to reverse (may be more than 1 pass), then one last time to join). But the for โฆ code only iterates through the string onceโstarts at the back, then when it reaches the front, itโs done. Of course, this is a โmicro-optimizationโโthe reality is that both methods are super fast and personally Iโd use the code from the video (readability > performance). But itโs still helpful to know that small code !== fast code. More on reddit.com
Videos
15:00
Reverse Words in a String Using Python | Step-by-Step Tutorial ...
02:14
Reverse a String in Python in just one line of code | Reverse Words ...
Reverse The Words In A String | Python Example
04:16
Reverse Words in a String - LeetCode 151 - Python #leetcode75 - ...
10:18
Reverse Words in a String III - Leetcode 557 - Python - YouTube
08:21
REVERSE WORDS IN A STRING | LEETCODE 151 | PYTHON SOLUTION - YouTube
Interviewing.io
interviewing.io โบ questions โบ reverse-words-in-a-string
Reverse Words in a String (Python)
Because strings are immutable in Python, you wouldnโt be able to reverse the string in place. As such, you can use the approach where you split the string on spaces, reverse each word, and then join them back, like so:
Published ย March 10, 2020
CodeSignal
codesignal.com โบ learn โบ courses โบ practicing-string-operations-and-type-conversions-in-python โบ lessons โบ manipulating-strings-reversing-words-in-a-sentence
Manipulating Strings: Reversing Words in a Sentence
Consider a string filled with words. Your task is to write a Python function that accepts such a string. It then takes each of those words, reverses their character order, and, finally, stitches them all together to form a new string with reversed words.
Fanyang Meng's Blog
fanyangmeng.blog โบ reverse-words-in-a-string
151. Reverse Words in a String
December 13, 2024 - Multiple spaces between words (handled by split()) ... It's a great example of utilizing Python's built-in string manipulation features effectively. However, it's worth noting that while this solution is very Pythonic and readable, it may use more memory than necessary since each operation creates a new string. class Solution: def reverseWords(self, s: str) -> str: words = s.split() left, right = 0, len(words) - 1 while left < right: words[left], words[right] = words[right], words[left] left += 1 right -= 1 return " ".join(words)
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.
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.
STechies
stechies.com โบ reverse-words-string-python
How to Reverse Words in a String Python
January 8, 2020 - # Program to explain reverse Word in String or Sentence # Using for split() function # Define a function def reverse_word(string): # Split string with blank space # And convert to list rlist=string.split() # Reverse list using reverse function rlist.reverse() # Convert list to string with space return " ".join(rlist) string = 'This is Our Website Stechies' # Print Original and Reverse string print('Original String: ', string) print('Reverse String: ', reverse_word(string))
GeeksforGeeks
geeksforgeeks.org โบ python โบ python-reverse-all-strings-in-string-list
Reverse All Strings in String List in Python - GeeksforGeeks
July 12, 2025 - Explanation: We iterate over each string s in list a and reverse it using slicing (s[::-1]), then append the reversed string to res list.
GeeksforGeeks
geeksforgeeks.org โบ dsa โบ reverse-individual-words
Reverse individual words - GeeksforGeeks
To reverse individual words in a string, we can use built-in functions like stringstream in C++, StringBuilder in Java, split in Python and other languages.
Published ย March 17, 2025
Linode
linode.com โบ docs โบ guides โบ how-to-reverse-a-string-in-python
How to Reverse a String in Python | Linode Docs
May 13, 2022 - def reverse_string_my_way(string_in, reversal_style="slice"): # Use a for loop if indicated by reversal_style. if reversal_style == "loop": string_out_list = [] for item in string_in: string_out_list.insert(0, item) string_out = "".join(string_out_list) # Use the reversed function if indicated by reversal_style. elif reversal_style == "reversed": reversed_iterator = reversed(string_in) string_out = "".join(list(reversed_iterator)) # Reverse the order of words, rather than characters, in # the string if indicated by reversal_style. elif reversal_style == "word": word_list = string_in.split(" ")
Python documentation
docs.python.org โบ 3 โบ tutorial โบ controlflow.html
4. More Control Flow Tools โ Python 3.14.6 documentation
Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Pythonโs for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. For example (no pun intended): >>> # Measure some strings: >>> words = ['cat', 'window', 'defenestrate'] >>> for w in words: ...
GeeksforGeeks
geeksforgeeks.org โบ python โบ python-reverse-slicing-of-given-string
Python - Reverse Slicing of given string - GeeksforGeeks
July 12, 2025 - Using slicing with [::-1] in Python, we can reverse a string or list. This technique works by specifying a step of -1, which starts at the end of the sequence and moves backward, effectively reversing the order of elements.