What happens when start value < end value with range() cmd in Python?

The range command returns a list of values. If your ‘start’ is greater than your ‘end’ value, an empty list is returned.

The default increment value is positive 1. You can, however, use a third argument as the increment value. You can pass it as -1, and then the range() will return a decreasing value, as you’re looking for.

This is for Python 2. In Py3, things are similar yet different.

Browse More Popular Posts

Leave a Comment