Last modified: Mar 28, 2026 By Alexander Williams

Is Python Range Inclusive? Stop Value Explained

New Python programmers often ask a key question. Is the range function inclusive? The short answer is no. The range function in Python does not include the stop value by default.

This behavior can cause confusion. It is a common source of off-by-one errors. Understanding this is crucial for writing correct loops.

How the Python Range Function Works

The built-in range function generates a sequence of numbers. It is commonly used in for loops. The sequence starts from a given number and stops before another.

The basic syntax is range(start, stop, step). Only the stop argument is required. The start defaults to 0. The step defaults to 1.

For a deeper dive into its parameters, see our Python Range Function Guide: Syntax & Examples.

The most important rule is this: the sequence includes the start value but excludes the stop value. The stop value acts as an upper limit that is not reached.

Demonstrating the Non-Inclusive Behavior

Let's look at a simple example. This will clearly show how range works.


# Example 1: Basic range from 0 to 5
for i in range(5):
    print(i)
    

0
1
2
3
4
    

The loop printed numbers 0 through 4. It stopped before reaching 5. The stop value 5 was not included in the output.

Here is another example with a defined start and stop.


# Example 2: Range from 2 to 6
for i in range(2, 6):
    print(i)
    

2
3
4
5
    

The sequence started at 2. It included 2. It stopped at 6, meaning it printed up to 5. The number 6 was excluded.

Why Is Python Range Not Inclusive?

This design choice has historical and practical reasons. It aligns with zero-based indexing, which is common in programming. It also makes certain calculations more intuitive.

Consider iterating over a list's indices. A list with 5 elements has indices 0, 1, 2, 3, and 4. Using range(len(my_list)) works perfectly. It generates indices from 0 to 4.


my_list = ['a', 'b', 'c', 'd', 'e']
for index in range(len(my_list)):
    print(f"Index {index}: {my_list[index]}")
    

Index 0: a
Index 1: b
Index 2: c
Index 3: d
Index 4: e
    

If range were inclusive, range(5) would go to 5. This would cause an IndexError when trying to access my_list[5].

How to Make a Range Inclusive in Python

You often need a sequence that includes the final number. You cannot change the built-in range function. But you can easily adjust its arguments to get an inclusive range.

The standard method is to add 1 to the stop value. If you want numbers from 1 to 10 inclusive, use range(1, 11).


# Creating an inclusive range from 1 to 10
inclusive_numbers = list(range(1, 11))
print(inclusive_numbers)
    

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    

For more techniques and detailed examples, check out our guide on Python Range Inclusive: How to Include the Stop Value.

Practical Examples with Inclusive Ranges

Let's apply this knowledge to real tasks. These examples show why inclusive control matters.

Example 1: Printing a Countdown

You want to print "3...2...1...Go!". You need to include the number 1.


# Countdown from 3 to 1 (inclusive)
for num in range(3, 0, -1): # Start at 3, stop before 0, step -1
    print(f"{num}...")
print("Go!")
    

3...
2...
1...
Go!
    

Example 2: Iterating Over a Specific Slice

You have a list of days. You want to process from Wednesday to Friday inclusive.


days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
# Indices: Wed=2, Fri=4. To include index 4, stop must be 5.
for i in range(2, 5):
    print(days[i])
    

Wed
Thu
Fri
    

Common Pitfalls and How to Avoid Them

Forgetting that range is exclusive leads to bugs. Here are common mistakes and fixes.

Pitfall 1: Missing the Last Item in a Loop


# Incorrect: Will only process up to item 4.
items = 5
for i in range(1, items): # This gives 1, 2, 3, 4
    process_item(i)

# Correct: To process items 1 through 5 inclusive.
for i in range(1, items + 1): # This gives 1, 2, 3, 4, 5
    process_item(i)
    

Pitfall 2: Creating the Wrong List Length


# Want a list of 10 numbers starting at 0: [0..9]
my_list = list(range(0, 10)) # Correct. Stop is 10.
print(len(my_list)) # Outputs 10

# If you mistakenly think range is inclusive:
my_list_wrong = list(range(0, 9)) # This only has 9 items!
print(len(my_list_wrong)) # Outputs 9
    

Conclusion

The Python range function is a powerful tool. It is not inclusive of its stop value by design. This behavior supports clean indexing and prevents errors.

Remember the simple rule: range(start, stop) goes from start up to, but not including, stop.

To create an inclusive range, just add 1 to your intended stop value. This small adjustment is the key to mastering sequence generation in Python.

Keep this exclusive nature in mind. It will help you write more accurate and bug-free loops in your code.