This is impossible to do with Python's range. But this can be accomplished by creating your own generator function.

def myRange(start,end,step):
    i = start
    while i < end:
        yield i
        i += step
    yield end


for i in myRange(0,99,20):
    print(i)

Output:

0
20
40
60
80
99
Answer from Neil on Stack Overflow
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
While loop from 1 to infinity, therefore running forever. x = 1 while True: print("To infinity and beyond! We're getting close, on %d now!" % (x)) x += 1 ยท When running the above example, you can stop the program by pressing ctrl+c at the same time. As you can see, these loop constructs serve different purposes.
Discussions

python - loop at exact time intervals - Stack Overflow
I want to run a piece of code at exact time intervals (of the order of 15 seconds) Initially I used time.sleep(), but then the problem is the code takes a second or so to run, so it will get out of... More on stackoverflow.com
๐ŸŒ stackoverflow.com
iteration - How to properly iterate over intervals in Python? - Stack Overflow
I am quite new to Python (I'm more used to C, C#). I am trying to learn and I want to try to do things as 'Pythonic' as possible. I want to iterate over intervals and then do something based on wh... More on stackoverflow.com
๐ŸŒ stackoverflow.com
how would I iterate over a list at set intervals?
That is commonly called a "grouper". There is a nice example in the itertools recipes but for lists it's often easier just to use range slicing. groups = [my_list[i:i+2] for i in range(0, len(my_list), 2)] Edit: Combined with a little unpacking magic, I think this is what you want: >>> my_list=[('x',9.99),('y',12.55),('p',9.99),('i',55.55)] >>> groups = (my_list[i:i+2] for i in range(0, len(my_list), 2)) >>> for (_,a),(_,b) in groups: ... print(f"{a} + {b} = {a+b:.2f}") ... 9.99 + 12.55 = 22.54 9.99 + 55.55 = 65.54 More on reddit.com
๐ŸŒ r/learnpython
3
1
January 20, 2022
time - Python loop to run for certain amount of seconds - Stack Overflow
I have a while loop, and I want it to keep running through for 15 minutes. it is currently: while True: #blah blah blah (this runs through, and then restarts. I need it to continue doing this ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Python
peps.python.org โ€บ pep-0284
PEP 284 โ€“ Integer for-loops | peps.python.org
March 1, 2002 - Python provides functions range() and xrange() to generate lists and iterators for such intervals, which work best for the most frequent case: half-open intervals increasing from zero.
๐ŸŒ
GitHub
github.com โ€บ morefigs โ€บ interval-timer
GitHub - morefigs/interval-timer: interval-timer is a Python package that enables iterating over a sequence of regular time intervals with high precision.
from interval_timer import IntervalTimer # Iterates exactly every half second for interval in IntervalTimer(0.5, stop=5): print(interval) interval-timer uses perf_counter under the hood to obtain high precision timing.
Author ย  morefigs
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_range.asp
Python Looping Through a Range
Python Examples Python Compiler ... Glossary ยท To loop through a set of code a specified number of times, we can use the range() function, The range() function returns a sequence of numbers, starting from 0 by default, and ...
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ python-range
Python range(): Represent Numerical Ranges โ€“ Real Python
November 24, 2024 - Master the Python range() function and learn how it works under the hood. You most commonly use ranges in loops. In this tutorial, you'll learn how to iterate over ranges but also identify when there are better alternatives.
๐ŸŒ
Snakify
snakify.org โ€บ for loop with range
For loop with range - Learn Python 3 - Snakify
To iterate over a decreasing sequence, we can use an extended form of range() with three arguments - range(start_value, end_value, step). When omitted, the step is implicitly equal to 1. However, can be any non-zero value.
๐ŸŒ
Raspberry Pi Forums
forums.raspberrypi.com โ€บ board index โ€บ hardware and peripherals โ€บ raspberry pi pico โ€บ micropython
Executing the code in a loop at a fixed interval. - Raspberry Pi Forums
>>> paste mode; Ctrl-C to cancel, Ctrl-D to finish === import sys, time === import uos === === def something(_count): === time.sleep_ms(uos.urandom(1)[0] >> 2) === === _count = 0 === _interval = 100 === while True: === time.sleep_ms(_interval - int(time.ticks_ms() % _interval)) === print(time.ticks_ms()) === something(_count) === _count += 1 2471500 2471600 2471700 2471800 2471900 2472001 2472101 2472200 2472300 2472400 2472500
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_for_loops.asp
Python For Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 1879901 โ€บ python-loops-with-time-interval
Python loops with time interval | Sololearn: Learn to code for FREE!
July 11, 2019 - Something in here should be able to help you be more precise in the time calculation instead of trying to just create a loop to simulate a time delay. ... There is a time module with functions that you can use to handle tracking time or possibly using the sleep function dependent on how you want to design it. ... You can also use the builtin threading library to schedule repeated action in python, like write a function that calls itself after a certain amount of time. A simple example is here: https://stackoverflow.com/questions/8600161/executing-periodic-actions-in-python
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Loops
Loops - Learn Python - Free Interactive Python Tutorial
... # Prints out 0,1,2,3,4 and then it prints "count value reached 5" count=0 while(count<5): print(count) count +=1 else: print("count value reached %d" %(count)) # Prints out 1,2,3,4 for i in range(1, 10): if(i%5==0): break print(i) else: ...
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ for-loop
Python for Loop (With Examples)
The continue statement skips the current iteration of the loop and continues with the next iteration. For example, languages = ['Swift', 'Python', 'Go', 'C++'] for lang in languages: if lang == 'Go': continue print(lang)
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - In this example, color is the loop variable, while the colors list is the target collection. Each time through the loop, color takes on a successive item from colors. In this loop, the body consists of a call to print() that displays the value on the screen. This loop runs once for each item in the target iterable. The way the code above is written is the Pythonic way to write it.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-for-loop-for-i-in-range-example
Python For Loop - For i in Range Example
March 30, 2021 - # Example for loop for i in [1, 2, 3, 4]: print(i, end=", ") # prints: 1, 2, 3, 4, We can include more complex logic in the body of a for loop as well.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ loops-python-tutorial
Python Loops Tutorial: For & While Loop Examples | DataCamp
October 18, 2017 - # Print "Thank you" 5 times for number in range(5): print("Thank you") # Thank you # Thank you # Thank you # Thank you # Thank you ยท As you can see, the components that you saw in the above section return in this small example of a for loop in Python: the for keyword, the variable number, the in keyword, the range() function and the code that you want to execute multiple times, print("Thank you")....