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
๐ŸŒ
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 ...
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
python - How do I loop through a list by twos? - Stack Overflow
I want to loop through a Python list and process 2 list items at a time. Something like this in another language: for(int i = 0; i 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
Be aware that interval isn't that ... < 1 sec). So if your job takes 500 ms and you ask for an interval of 1 sec, you'll get called at: 0, 500ms, 2000ms, 2500ms, 4000ms and so on. One could fix this by measuring time in a loop rather than sleep() ...... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Snakify
snakify.org โ€บ for loop with range
For loop with range - Learn Python 3 - Snakify
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. The last number is not included. There's a reduced form of range() - range(max_value), in which case min_value is implicitly set to zero:
๐ŸŒ
Real Python
realpython.com โ€บ python-range
Python range(): Represent Numerical Ranges โ€“ Real Python
November 24, 2024 - for i in range(5) is a loop that iterates over the numbers from 0 to 4, inclusive. The range parameters start, stop, and step define where the sequence begins, ends, and the interval between numbers.
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
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. The for loop runs for a fixed amount of times, while the while loop runs until the loop condition changes.
๐ŸŒ
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. It will not suffer from drift over long time periods. If an interval iteration is delayed due to slow code execution, then future intervals will still be synchronised to absolute time if they're given time to catch up.
Author ย  morefigs
Find elsewhere
๐ŸŒ
Llego
llego.dev โ€บ home โ€บ blog โ€บ using range() in for loops to control iterations in python
Using range() in for Loops to Control Iterations in Python - llego.dev
May 26, 2023 - This will print integers from 1 up to but not including 10. Great for looping a set number of times. Adding a step or stride controls the interval between numbers:
๐ŸŒ
Python
peps.python.org โ€บ pep-0284
PEP 284 โ€“ Integer for-loops | peps.python.org
March 1, 2002 - One of the most common uses of for-loops in Python is to iterate over an interval of integers. Python provides functions range() and xrange() to generate lists and iterators for such intervals, which work best for the most frequent case: half-open ...
๐ŸŒ
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
๐ŸŒ
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 - 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 ... Thank you very much Tibor ! ... Suggestion or Tips for some small Tasks or projects for python for beginner friendly.
๐ŸŒ
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).
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python range() explained with examples
Python range() Function Explained with Examples
March 17, 2022 - Letโ€™s see how to loop in a reverse iteration or backward iteration to display a range of numbers from 5 to 0. # reverse range using negative step # start = 5 # stop = -1 # step = -1 for i in range(5, -1, -1): print(i)Code language: Python (python) Run
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-for-loop-for-i-in-range-example
Python For Loop - For i in Range Example
March 30, 2021 - If range() is called with only one argument, then Python assumes start = 0. The stop argument is the upper bound of the range. It is important to realize that this upper value is not included in the range. In the example below, we have a range starting at the default value of 0 and including integers less than 5. # Example with one argument for i in range(5): print(i, end=", ") # prints: 0, 1, 2, 3, 4,
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - This type of loop lets you traverse different data collections and run a specific group of statements on or with each item in the input collection. In Python, for loops are compound statements with a header and a code block that runs a predefined number of times.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 63804587 โ€บ how-to-print-intervals-of-data-in-a-for-loop-if-else-statement-python-questio
How to print intervals of data in a for loop (if else statement)? Python Question - Stack Overflow
September 9, 2020 - Essentially, I want to find a way for the code to show intervals of time. So instead of minute by minute, it would be more like: ... From spacepy import cdf import datetime from numpy import * import numpy as np cdf = pycdf.CDF('/directory/file.cdf') print(cdf) TIME = cdf['EPOCH'] LAT = cdf['SouthBtrace_GM_LAT'] LON = cdf['SouthBTrace_GM_LON'] #Loop Count count = 0 with open("example.txt", "a") as testing: for i, j in zip(LAT, LON): if(-65.26 <= i <= -59.26 and 32.31 <= j <= 52.31): count +=1 n = count testing.write(str(TIME[n-1])+'\t'+str(i)+'\t'+str(j)+ '\n') else: count +=1
๐ŸŒ
Microsoft MakeCode
makecode.microbit.org โ€บ reference โ€บ loops โ€บ every-interval
every Interval
interval: a number that is the amount of time in milliseconds to wait before running the loop again. Both the every loop and the forever loop are event-based loops where the code inside is run as part of a function.