# Backward iteration in Python

## Backward iteration in Python

The iteration of numbers is done by looping techniques in Python. There are many techniques in Python which facilitate looping. Sometimes we require to perform the looping backward and having shorthands to do so can be quite useful. Let’s discuss certain ways in which this can be done.

Method #1 : Using `reversed()`
The simplest way to perform this is to use the reversed function for the `for` loop and the iteration will start occurring from the rear side than the conventional counting.

 `# Python3 code to demonstrate ` `# backward iteration` `# using reversed()` ` ` `# Initializing number from which ` `# iteration begins ` `N ``=` `6` ` ` `# using reversed() to perform the back iteration` `print` `(``"The reversed numbers are : "``, end ``=` `"")` `for` `num ``in` `reversed``(``range``(N ``+` `1``)) :` `    ``print` `(num, end ``=` `" "``)`

Output :

```The reversed numbers are : 6 5 4 3 2 1 0
```

Method #2 : Using `range(N, -1, -1)`
This particular task can also be performed using the conventional range function which, if provided with the third argument performs the skip and second argument is used to start from backwards.

 `# Python3 code to demonstrate ` `# backward iteration` `# using range(N, -1, -1)` ` ` `# Initializing number from which ` `# iteration begins ` `N ``=` `6` ` ` `# using reversed() to perform the back iteration` `print` `(``"The reversed numbers are : "``, end ``=` `"")` `for` `num ``in` `range``(N, ``-``1``, ``-``1``) :` `    ``print` `(num, end ``=` `" "``)`

Output :

```The reversed numbers are : 6 5 4 3 2 1 0
```

Last Updated on October 28, 2021 by admin

## Create a Countdown Timer Using PythonCreate a Countdown Timer Using Python

How To Create a Countdown Timer Using Python? In this article, we will see how

## Python – os.path.relpath() methodPython – os.path.relpath() method

Python | os.path.relpath() method OS module in Python provides functions for interacting with the operating system.

## Creating a Pandas Series from ListsCreating a Pandas Series from Lists

Creating a Pandas Series from Lists   A Series is a one-dimensional labeled array capable

## Python | Binding function in TkinterPython | Binding function in Tkinter

Python | Binding function in Tkinter Tkinter is a GUI (Graphical User Interface) module that is

## Accessing elements of a Pandas SeriesAccessing elements of a Pandas Series

Accessing elements of a Pandas Series Pandas Series is a one-dimensional labeled array capable of

## Substitution CipherSubstitution Cipher

Substitution Cipher Hiding some data is known as encryption. When plain text is encrypted it

## Rename multiple files using PythonRename multiple files using Python

Rename multiple files using Python In Python3, rename() method is used to rename a file or directory.