ProjectsArticle

✨ Why range() Is So Useful

How Python's range() function makes loops easier to control and why it has become one of the most useful tools I've learned.

Sep 24, 2026 • 8:28 PM • 4 min read

All dates and times are in CT

ResearchLearning

Why range() Is So Useful

When I first started using `for` loops, I kept seeing something called `range()`.

At first, I thought it was just another Python function I had to memorize.

But after using it more, I realized that `range()` is one of the most useful tools for controlling loops.

It gives me a simple way to create a sequence of numbers for a loop to work through.

What Does range() Do?

The `range()` function generates a sequence of numbers. It is commonly used with `for` loops when I want to repeat something a specific number of times. (docs.python.org)

For example, `range(5)` produces the numbers:

0, 1, 2, 3, 4

One thing that confused me at first was that the ending number isn't included.

So `range(5)` does not include 5.

It stops right before it.

Why Does It Start at 0?

By default, `range()` starts at 0.

That means:

`range(5)`

gives:

0, 1, 2, 3, 4

This can seem weird at first, especially when you're thinking about counting normally.

But starting at 0 is extremely useful in programming because many things in Python use zero-based positions.

Once I got used to it, it became much easier.

Starting and Ending Numbers

I don't always have to start at 0.

I can give `range()` a starting number and an ending number.

For example, `range(3, 8)` produces:

3, 4, 5, 6, 7

The start is included, but the stop value is not. (docs.python.org)

This gives me much more control over which numbers my loop uses.

The Step

There is also a third part of `range()` called the step.

The step controls how much the number changes each time.

For example, a range can count by 2 instead of 1.

That means I can create sequences such as:

0, 2, 4, 6, 8

I can also use a negative step to count backward. Python's documentation supports positive and negative step values for `range()`. (docs.python.org)

This makes `range()` useful for much more than simply counting upward.

range() and for Loops

One of the main reasons I use `range()` is with `for` loops.

If I want a loop to run a certain number of times, `range()` gives the loop the numbers it needs.

For example, I could use it to create a multiplication table, print a pattern, or repeat a calculation.

Instead of manually deciding what happens during every repetition, I can let the range control the sequence.

That's a lot easier.

range() Doesn't Create a Giant List

Something interesting about `range()` is that it doesn't have to create a huge list of every number it represents.

A range object keeps track of the pattern using its start, stop, and step values and produces the values as needed when it is iterated over. This helps it use a small amount of memory even for large ranges. (docs.python.org)

I didn't realize this when I first started using it.

I just thought `range(1000000)` meant Python immediately created a million-number list.

It doesn't work that way.

Common Mistakes

One of the easiest mistakes with `range()` is forgetting that the stop value isn't included.

For example:

`range(1, 11)`

goes from 1 through 10, not 11.

Another common mistake is forgetting that the default starting value is 0.

These small details can completely change what a loop does.

Why I Use It So Much

As I started doing more Python problems, I noticed `range()` appearing everywhere.

It's useful for:

* Counting
* Repeating actions
* Creating patterns
* Multiplication tables
* Working with positions
* Counting backward
* Controlling how many times a loop runs

It is a small function, but it can control a huge number of different programs.

Reflection

At first, `range()` seemed like something I just needed to memorize.

Now I see it as a tool that gives me control over loops.

Once I understood the start, stop, and step values, it became much easier to predict exactly what a loop would do.

`range()` may look simple, but it gives loops a lot of power.

Feedback

Was this article useful?

Discussion

Comments

No comments yet. Be the first to add one.