When you call range() with two arguments, the first argument is the starting number, and the second argument is the end (non-inclusive). So you're starting from len(list_of_numbers), which is 5, and you're ending at 6. So it just prints 5.

To get the results you want, the starting number should be 0, and the end should be len(list_of_numbers)+1. If you call it with one argument, that's the end, and 0 is the default start. So use

Copyfor i in range(len(list_of_numbers)+1):

or if you want to pass the start explicitly:

Copyfor i in range(0, len(list_of_numbers)+1):
Answer from Barmar on Stack Overflow
🌐
Snakify
snakify.org › for loop with range
For loop with range - Learn Python 3 - Snakify
For instance, any string in Python is a sequence of its characters, so we can iterate over them using for: ... Another use case for a for-loop is to iterate some integer variable in increasing or decreasing order. Such a sequence of integer can be created using the function range(min_value, max_value): ... Function range(min_value, max_value) generates a sequence with numbers min_value, min_value + 1, ..., max_value - 1.
Discussions

Python: for i in range (1, 10), print (i). Why does it not print the number 10?
First arg is including. Srcond one is excluding More on reddit.com
🌐 r/eli5_programming
6
3
October 29, 2021
Loops - for i and for j in range(n) explained
It may seem special, but its just a normal for loop. You can call the range() function separately from these loops to generate a range object. These are iterables, and can be converted into lists, tuples, etc. Try doing something like print(list(range(5))), and it will show [0, 1, 2, 3, 4]. You can think of it just being a normal list, like this: for i in range(5): print(i) for i in [0, 1, 2, 3, 4]: print(i) So to answer your other question about for j in range(i), think about it this way. for i in range(3): for j in range(i): print(j) The first time this runs, i will be 0 and it will increase by 1 every time it the loop runs, so it will be running for i in range(0) the first time, for i in range(1) the second time, and so on. range() accepts 3 arguments, start, stop, and step. Lets do some examples list(range(10)) # stop at 10 # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] list(range(5, 10)) # start at 5, end at 10 # [5, 6, 7, 8, 9] list(range(0, 10, 2)) # start at 0, end at 10, increment by 2 each time # [0, 2, 4, 6, 8] Hopefully this explains it a bit more! More on reddit.com
🌐 r/learnpython
6
8
July 3, 2021
python - Decrementing for loops - Stack Overflow
I want to have a for loop like so: for counter in range(10,0): print counter, and the output should be 10 9 8 7 6 5 4 3 2 1 More on stackoverflow.com
🌐 stackoverflow.com
Python's range function. Why doesn't (1-10) include the integer 10?
The easiest way to think about it for me is this... Python is 0 indexed for everything. So if I want a range with 10 digits, I would say range(10). But that means that it's 0 ... 9 in order to get 10 digits. And it's that 0 indexed part that has to be consistent. So range(10) = range(0, 10). And then extrapolated it is range(start, stop) -> but start is inclusive and stop is exclusive in order to remain consistent across the board. This might seem odd when taken in isolation, but the fact that Python is 0 indexed everywhere means that you can use the range function combined with the length of lists and other things much easier. More on reddit.com
🌐 r/learnpython
7
1
September 28, 2017
🌐
Python
wiki.python.org › moin › ForLoop
ForLoop - Python Wiki
When you have a block of code you ... of times, you use what is known as a "nested loop". In Python, these are heavily used whenever someone has a list of lists - an iterable object within an iterable object. for x in range(1, 11): for y in range(1, 11): print('%d * %d = %d' ...
🌐
W3Schools
w3schools.com › python › gloss_python_for_range.asp
Python Looping Through a Range
The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3): ... Python For Loops Tutorial For Loop Through a String For Break For Continue ...
🌐
Bobby Hadz
bobbyhadz.com › blog › python-for-loop-1-to-10
For or While loop to print Numbers from 1 to 10 in Python | bobbyhadz
April 9, 2024 - Use the `range()` class to loop from 1 to 10 in a `for` loop, e.g. `for num in range(1, 11):`.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-range-function
Python range() function - GeeksforGeeks
It is most commonly used in loops to control how many times a block of code runs. Note: range() returns a lazy iterable, not a full list. It generates numbers dynamically instead of storing them all in memory.. To access elements like a list, convert it using list(range(...)). Example: This example shows the use of range() to generate numbers starting from 0 up to (but not including) a given value. ... Example 1: This example generates numbers starting from a custom value and ending before another value.
Published   March 10, 2026
Find elsewhere
🌐
StrataScratch
stratascratch.com › blog › python-for-loop-range-function
How Does Python For Loop Range Function Work? - StrataScratch
November 5, 2025 - Solution Walkthrough: We iterate through all numbers from 10 to 1000. ... To easily reverse and compare, we convert the number to a string. ... Python's slice notation [::-1] reverses a string. This reads the string from end to beginning with a step of -1. ... If the original string equals the reversed string, it's a palindrome. ... Here is the entire solution, where we add print for readability. print("Palindrome numbers between 1 and 1000:") for num in range(1, 1001): num_str = str(num) if num_str == num_str[::-1]: print(num, end=" ")
🌐
PYnative
pynative.com › home › python › python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - Using this example, we can understand how the iterator variable i is getting value when we use range() with for loop. for i in range(1, 10, 2): print("Current value of i is:", i)Code language: Python (python) Run
🌐
Django Central
djangocentral.com › python-program-to-print-numbers-from-1-to-10-using-for-loop
Python Program To Print Numbers From 1 to 10 Using For Loop
The for loop is used to iterate through the range of numbers from 1 to 10 (inclusive). The range() function generates a sequence of numbers, starting from the first argument (1) up to, but not including, the second argument (11), similar to list indexing in range starts from 0 which means range( ...
🌐
Reddit
reddit.com › r/learnpython › loops - for i and for j in range(n) explained
r/learnpython on Reddit: Loops - for i and for j in range(n) explained
July 3, 2021 -

I'm a Python beginner and wondering if anyone can explain what the for j in range i line is doing here? In addition, what is the proper name for these i and j expressions?

n=5;
for i in range(n):
    for j in range(i):
        print ('* ', end="")
    print('')
for i in range(n,0,-1):
    for j in range(i):
        print('* ', end="")
    print('')
🌐
Learn Python
learnpython.org › en › Loops
Loops - Learn Python - Free Interactive Python Tutorial
For loops can iterate over a sequence of numbers using the "range" and "xrange" functions. The difference between range and xrange is that the range function returns a new list with numbers of that specified range, whereas xrange returns an ...
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 5-2-for-loop
5.2 For loop - Introduction to Python Programming | OpenStax
March 13, 2024 - A range() function generates a sequence of integers between the two numbers given a step size. This integer sequence is inclusive of the start and exclusive of the end of the sequence.
🌐
freeCodeCamp
freecodecamp.org › news › python-for-loop-for-i-in-range-example
Python For Loop - For i in Range Example
March 30, 2021 - As discussed in Python's documentation, for loops work slightly differently than they do in languages such as JavaScript or C. A for loop sets the iterator variable to each value in a provided list, array, or string and repeats the code in the body of the for loop for each value of the iterator variable. In the example below, we use a for loop to print every number in our array. # Example for loop for i in [1, 2, 3, 4]: print(i, end=", ") # prints: 1, 2, 3, 4,
🌐
Real Python
realpython.com › python-for-loop
Python for Loops: The Pythonic Way – Real Python
February 23, 2026 - Python’s for loop iterates over items in a data collection, allowing you to execute code for each item. To iterate from 0 to 10, you use the for index in range(11): construct.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › range() in for loop in python
range() in for loop in Python - Spark By {Examples}
May 31, 2024 - Let’s specify start and stop parameters in the range() function and iterate them using the for loop. This is typically used when you wanted to run a block of code a certain number of times.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-range.html
Python range() Function
>>> s = 'Python' >>> len(s) 6 >>> for i in reversed(range(len(s))): ... print(i, s[i]) ... 5 n 4 o 3 h 2 t 1 y 0 P · Range with 2 parameters specifies a start number other than 0, but is otherwise like the 1 parameter form above, going up to but not including the stop number. >>> list(range(5, 10)) [5, 6, 7, 8, 9] >>> list(range(5, 7)) [5, 6] >>> list(range(5, 6)) [5] >>> list(range(5, 5)) # start >= stop, no numbers [] >>> list(range(0, 5)) [0, 1, 2, 3, 4] >>> list(range(0, 0)) [] >>> list(range(0, -1)) []
🌐
PyTutorial
pytutorial.com › python-for-loop-range-a-beginners-guide
PyTutorial | Python For Loop Range: A Beginner's Guide
2 weeks ago - Iteration number: 0 Iteration number: 1 Iteration number: 2 Iteration number: 3 Iteration number: 4 · The loop runs exactly 5 times, with 'i' taking values from 0 to 4. This is the most common use case. With two arguments, you define a starting point. range(start, stop) begins at the 'start' number. It ends before the 'stop' number. # Loop from 5 to 9 for i in range(5, 10): print(i)
🌐
CodeBasics
code-basics.com › programming › python course › for loop and range function
For loop and range function | Python | CodeBasics
At each step we add the value of ... i by 1. As soon as i becomes equal to 10, the loop ends and the program gives us the sum of all numbers from 0 to 9 equal to 45. ... The first example uses while, which keeps running until i < 10. The second uses for and iterates from 0 to 9 using range(). Both do the same thing: add the numbers from 0 to 9 to the sum variable, but they use different ways to iterate. The range function in Python is a built-in ...