# How to Loop Backwards in Python: Easy Methods

Do you want to loop backward in python and print on the screen? If yes then in this post you will know how to loop backward in python using different functions. You will know how to use the reversed() function to loop backward. As you already know that for loop allows you to iterate in the forward direction. But if you use the reversed() function with the range() function then you will easily loop backwards in Python.

## Methods to Loop Backwards in Python

Let’s know all the methods that can help you in looping backward in python.

### Method 1: Loop backward using the reversed() Function

As you already know if you will use the for loop with the range(1,10) will loop and print elements from 1 to 9. But if you want to loop in the backward direction then enclose the range(1,10) function inside the reversed() function. The below lines of code will print the values inside the range in the reverse direction.

``````for i in reversed(range(1,10)):
print(i)
``````

Output

### Method 2: Using the range() function

You can also loop backward using the range() function. Here you have to tell the function to iterate in the opposite direction by passing the arguments as last, first, and -1 respectively.

Use the below lines of code to achieve that.

``````for i in range(9,0,-1):
print(i)
``````

Output

### Method 3: Slice the list for the backward loop

If you have a list and want to print each element in reverse direction then you can use the list slicing. Here you will pass the -1::-1 inside the square bracket and print the elements from the last. Here -1 denotes the index for the end element and 0 for the first element.

You will get the elements printed in the reverse direction when you will run the below lines of code.

``````list=[10, 20, 50, 30, 40]
for i in list[-1::-1]:
print(i)
``````

Output

## Conclusion

Sometimes you may have to loop backward in python. For example, to access the last element of the list you will use the -1:0 to get the last. The above methods use the reversed() and range() functions to loop backward in the reverse direction.

I hope you have liked this tutorial. If you have any queries then you can contact us for more help