About 168,000 results
Open links in new tab
  1. 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?

  2. Python reversing a string using recursion - Stack Overflow

    Additionally, Python imposes a limit on stack size, and there's no tail call optimization, so a recursive solution would be limited to reversing strings of only about a thousand characters. You can increase …

  3. python - Understanding string reversal via slicing - Stack Overflow

    Python will "do the right thing" when filling in the start and stop so it iterates through the list backwards and gives you [10,9,8,7,6,5,4,3,2,1]. I've given the examples with lists, but strings are just another …

  4. Best way to loop over a python string backwards

    Aug 9, 2015 · What is the best way to loop over a python string backwards? The following seems a little awkward for all the need of -1 offset: string = "trick or treat" for i in range(len(string)-1, 0-1, -1): ...

  5. What is the most efficient way to reverse a string in Python?

    Jun 26, 2023 · If you look at Python's intermediate code (see Godbolt Compiler Explorer), you can also see that slicing is its own operation, so it's pretty much optimized as well. So, s[::-1] is the …

  6. Reversing a string in Python using a loop? - Stack Overflow

    Dec 25, 2016 · Are you trying to reverse the string or print the characters in reverse order? Your title implies the former but your code seems to be trying to do the latter. If you want to reverse the string - …

  7. How do I reverse words in a string with Python - Stack Overflow

    May 21, 2017 · That's not in-place; you're just reversing the order of the letters in each word. "In place" has a very specific meaning when it comes to data structures; it means you're modifying the actual …

  8. python - Reverse a string without using reversed () or [::-1]? - Stack ...

    Sep 9, 2013 · I came across a strange Codecademy exercise that required a function that would take a string as input and return it in reverse order. The only problem was you could not use the reversed …

  9. Fastest way to reverse a string in python - Stack Overflow

    Apr 30, 2016 · I was able to come up with two different ways to reverse a string in Python. Common sense dictates that code with more lines should run slower. I reversed a the string in two ways. …

  10. python - Reverse each word in a string - Stack Overflow

    May 27, 2017 · 0 A version without Python-level looping and with reversing the whole string once instead of each word separately.