About 1,830,000 results
Open links in new tab
  1. Reverse Words in a Given String in Python - GeeksforGeeks

    Jan 6, 2025 · Using split () and join () is the most common method to reverse the words in a string. The split() method splits the string into a list of words. [::-1] reverses the list of words. …

  2. string - How to reverse words in Python - Stack Overflow

    Sep 18, 2013 · Use the slice notation: >>> string = "Hello world." You can read more about the slice notatoin here. A string in Python is an array of chars, so you just have to traverse the …

  3. Reversing words in a Python string (including punctuation)

    It's possible to pass a function as the repl argument to re.sub(), so we can use that to match words and reverse them: import re def rev_each_word_in(sentence): return re.sub(r'\b\S*\b', …

  4. Reverse Strings in Python: reversed(), Slicing, and More

    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 …

  5. How to reverse a String in Python - GeeksforGeeks

    Nov 21, 2024 · The slicing method (s[::-1]) is the most concise and efficient way to reverse a string. The reversed() function is easy to use and maintains readability. Looping & List …

  6. Python Program To Reverse Words In A Given String

    May 5, 2023 · Start by taking the input string as s. Reverse the entire string s using a two-pointer approach. Initialize two pointers, start and end, both pointing to the first character of the …

  7. 5 Best Ways to Reverse the Position of Each Word of a Given String

    Mar 10, 2024 · In this approach, the reverse_sentence_loop() function splits the sentence into words. It then iterates through the words in reverse, appending each one to a new string, and …

  8. Python Reverse String: A Comprehensive Guide - CodeRivers

    Jan 20, 2025 · The reversed() function in Python takes an iterable (such as a string) and returns a reverse iterator. To get the reversed string, you need to convert the iterator back to a string …

  9. How to Reverse Words in a String in Python - CodeSpeedy

    Split the string using split() function. Use the reverse() method to reverse all the words that have been split from the string. Finally, join and print them using the join() function.

  10. Python String Reversal

    String reversal has multiple use cases: 1. Slice Notation Method (Most Pythonic) return s[::-1] The slice notation [::-1] is the most concise and Pythonic way to reverse a string. The -1 step …

Refresh