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

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

or if you want to pass the start explicitly:

for 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

"for i in range()" to do an infinite loop with a counter - Ideas - Discussions on Python.org
Hi, Usually in Python we can avoid the i = 0 … i += 1 paradigm that we use in other languages when we need to count things, thanks to enumerate(...), for i in range(100), etc. Along the years I have nearly always found a more “pythonic” replacement for code containing i = 0 … i += 1. ... More on discuss.python.org
🌐 discuss.python.org
4
August 10, 2022
for loop in Python - Stack Overflow
In C/C++, I can have the following loop for(int k = 1; k 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
For loop syntax in Python without using range() or xrange() - Stack Overflow
Now what i want to know is that ... code in python without using range() or xrange(): for i in lst: for j in lst after element i: '''This is the line i want the syntax for''' #Do Something · The second loop is to access elements after the element i i.e., if i = 3, j would have to loop through from 4 to 10, so the pairs of numbers if i and j are printed would be (1,2)..(1,10), ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...
🌐
Python
wiki.python.org › moin › ForLoop
ForLoop
for x in range(0, 3): print("We're on time %d" % (x)) While loop from 1 to infinity, therefore running forever.
🌐
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   1 month ago
🌐
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=" ")
Find elsewhere
🌐
Python.org
discuss.python.org › ideas
"for i in range()" to do an infinite loop with a counter - Ideas - Discussions on Python.org
August 10, 2022 - Hi, Usually in Python we can avoid the i = 0 … i += 1 paradigm that we use in other languages when we need to count things, thanks to enumerate(...), for i in range(100), etc. Along the years I have nearly always found a more “pythonic” replacement for code containing i = 0 … i += 1. There is an exception with this code: an infinite loop with a counter: i = 0 while True: ... if breaking_condition: break i += 1 Proposal: could we accept that range() without any parameter ...
🌐
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
🌐
Quora
quora.com › In-Python-how-do-I-set-the-range-of-a-for-loop-to-repeat-until-a-break-is-reached
In Python, how do I set the range of a for loop to repeat until a break is reached? - Quora
this is the function . with this function you can change the range within the for loop .here when ever it come across a even no it increase the range by 1. you can change the condition like (i%2==0) and you’ll get the output you want ... I think this will solve your problem. ... How do you run Python code forever until you stop it (Python, loops, while loop, forever monitor, development)?
🌐
Note.nkmk.me
note.nkmk.me › home › python
Python for Loop (With range, enumerate, zip) | note.nkmk.me
August 18, 2023 - You don't need to convert it to a list in a for loop. The range() function accepts different numbers of arguments: ... print(list(range(6))) # [0, 1, 2, 3, 4, 5] print(list(range(10, 13))) # [10, 11, 12] print(list(range(0, 10, 3))) # [0, 3, ...
🌐
Betterdatascience
betterdatascience.com › python-for-loop-range
Python For Loop Range - How to Loop Through a Range in Python | Better Data Science
May 2, 2023 - A: By default, the range() function starts from 0. However, if you want to start a loop range at 1, you can simply specify 1 as the start argument while using the range() function.
🌐
Geek University
geek-university.com › home › use for loop with the range() function
Use for loop with the range() function | Python#
February 1, 2022 - The syntax of the range() function is: ... The start argument is the starting number. The stop argument is the last number (which is not included). The step argument is optional and defines the difference between each number in the sequence.
🌐
Codingem
codingem.com › home › python range() function: a complete guide (with examples)
Python range() Function: A Complete Guide (with Examples)
November 3, 2022 - For example, let’s generate a range of values from 50 to 100 with by using 10 as a step size: numbers = range(50,110,10) for number in numbers: print(number) ... Now that you know how to use the range() function in Python, let’s take a closer ...
🌐
Learn Python
learnpython.org › es › Loops
Bucles - Learn Python - Free Interactive Python Tutorial
# Imprime 0,1,2,3,4 y luego imprime "el valor de count alcanzó 5" count=0 while(count<5): print(count) count +=1 else: print("el valor de count alcanzó %d" %(count)) # Imprime 1,2,3,4 for i in range(1, 10): if(i%5==0): break print(i) else: print("esto no se imprime porque el bucle for se termina debido a un break pero no por fallar en la condición")
🌐
Reddit
reddit.com › r/learnpython › python's range function. why doesn't (1-10) include the integer 10?
r/learnpython on Reddit: Python's range function. Why doesn't (1-10) include the integer 10?
September 28, 2017 -

Hey all, so in my beginner programming attempts I have made a simple number game app in which the user enters a number that is stored as the "secret number" the computer attempts to guess in 10 trys. This number is a number between 1 and 10. So in order to anticipate the potential error of someone entering a number greater than 10, I have made used of the range function. "if secret_number not in numb_range re-enter secret number until number is within range 1-10" basically.

And it worked. except when I entered 10 it would continually ask me to re-enter as if 10 is not in the range 1-10. so when i made numb_range = range(1,11) the problem was solved.

Why is this? Thanks

🌐
Data Science Discovery
discovery.cs.illinois.edu › learn › Simulation-and-Distributions › For-Loops-in-Python
For-Loops in Python - Data Science Discovery
One hundred randomly generated numbers using random.radint(1, 6), using a for-loop. # Notice the use of `range(10)` to run this code 10 times:\nfor i in range(10):\n rank = random.choice( ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] )\n suit = random.choice( ["Club", "Heart", "Diamond", "Spade"] )\n print(f"{rank} of {suit}s")
🌐
Codegrepper
codegrepper.com › code-examples › python › for+loop+in+python+range
for loop in python range Code Example
May 20, 2020 - # Syntax - range(start, stop, step) - you must use integers, floats cannot be used for i in range(3): print(i) # output - automatically taken start = 0 and step = 1, we have given stop = 3 (excluding 3) for i in range(0, 4): print(i) # output - We have given start = 0 and stop = 4 (excluding 4), automatically taken step =1 for i in range(0, 5, 2): print(i) # output - We have given start = 0, stop = 5 (excluding 5), step = 2 for i in range(0, -4, -1): print(i) # output - We can go even backwards and also to negative numbers