About 25,400,000 results
Open links in new tab
  1. iteration - How to loop backwards in python? - Stack Overflow

    All of these three solutions give the same results if the input is a string: 1. result = "" for i in range(len(text),0,-1):

  2. Backward iteration in Python - GeeksforGeeks

    Nov 20, 2024 · Python provides various methods for backward iteration, such as using negative indexing or employing built-in functions like reversed(). Use reversed () method when we simply need to loop backwards without modifying original sequence or there is …

  3. Best way to loop over a python string backwards

    Aug 9, 2015 · It is not a very pythonic or even efficient way to loop over a string backwards. It does show how one could utilize range and negative step values to build a value by looping through a string and adding elements in off the end of the string to the front of the new value.

  4. python - Loop backwards using indices - Stack Overflow

    Jan 4, 2023 · And for the record the solution is to simply write: range(100)[::-1] (which is automatically translated to range(9, -1, -1)) - Tested in python 3.7. Try range(100,-1,-1), the 3rd argument being the increment to use (documented here). ("range" options, start, stop, step are documented here)

  5. Python For Loop in Backwards - Spark By Examples

    May 30, 2024 · Usually, Python for loop is implemented in a forward direction however sometimes you would be required to implement for loop in the backward direction. You can easily achieve this by using reversed () function and the range() function, with the negative step.

  6. Python for loop Backward | Example code - EyeHunts

    Sep 9, 2021 · Using reversed () or range (N, -1, -1) method to do for loop Backward iteration in Python. Simple example code looping backward and having shorthands to do it. Using reversed () function. Use the reversed function for the for loop and the iteration will start occurring from the last than the conventional counting. print(num, end=" ") Output:

  7. How to Iterate Backwards in Python - Delft Stack

    Mar 11, 2025 · One of the simplest ways to iterate backwards in Python is by using the built-in reversed() function. This function returns an iterator that accesses the given sequence in the reverse order. It can be applied to any sequence type, including lists, tuples, and strings. Here’s how you can use the reversed() function: Output:

  8. How to Loop Through a List Backwards in Python - Tutorial Kart

    To loop through a list backwards in Python, you can use methods like reversed (), slicing ( [::-1]), the range () function, or the iter () function with reversed ().

  9. Backward For Loop using Python | Aman Kharwal

    Oct 13, 2021 · Now coming back to using a for loop backwards, Python has an inbuilt function known as reversed () that can be used to reverse the order of a Python object while using a for loop. So below is how you can use a backward for loop using Python: The inbuilt function in Python known as reversed () can be used to use a for loop backwards.

  10. How to Loop Backward Iteration in Python - Delft Stack

    Mar 11, 2025 · Whether you’re dealing with lists, strings, or other iterable objects, Python provides several methods to achieve backward looping. We’ll explore these methods, complete with code examples and explanations, to help you understand how …

  11. Some results have been removed