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 โ€บ 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).
๐ŸŒ
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 ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_continue.asp
Python Continue For Loop
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 ... With the continue statement we can stop the current iteration of the loop, and continue with the next: ... fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x) Try it Yourself ยป
๐ŸŒ
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. The loop always includes start_value and excludes end_value during iteration:
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_sets_loop.asp
Python - Loop Sets
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 ยท โฎ Previous Next โฏ ยท You can loop through the set items by using a for loop: Loop through the set, and print the values: thisset = {"apple", "banana", "cherry"} for x in thisset: print(x) Try it Yourself ยป ยท
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_loop.asp
Python - Loop Lists
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 ... Learn more about for loops in our Python For Loops Chapter.
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Loops
Loops - Learn Python - Free Interactive Python Tutorial
While loops repeat as long as a certain boolean condition is met. For example: # Prints out 0,1,2,3,4 count = 0 while count < 5: print(count) count += 1 # This is the same as count = count + 1 ยท break is used to exit a for loop or a while loop, whereas continue is used to skip the current block, and return to the "for" or "while" statement.
๐ŸŒ
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 ...
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_challenges_for_loops.asp
Python For Loops Code Challenge
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 ... Test your understanding of Python for loops by completing a small coding challenge.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ loops-python-tutorial
Python Loops Tutorial: For & While Loop Examples | DataCamp
October 18, 2017 - Find a comprehensive tutorial for Python range loops, nested loops, and keywords. See For & While loops in action with Python now!
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ loops-in-python
Loops in Python - GeeksforGeeks
The continue statement in Python returns the control to the beginning of the loop. ... for letter in 'geeksforgeeks': if letter == 'e' or letter == 's': continue print('Current Letter :', letter)
Published ย  1 week ago
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_while_loops.asp
Python While 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 ... With the while loop we can execute a set of statements as long as a condition is true. ... Note: remember to increment i, or else the loop will continue forever.
๐ŸŒ
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
๐ŸŒ
Real Python
realpython.com โ€บ python-for-loop
Python for Loops: The Pythonic Way โ€“ Real Python
February 23, 2026 - Learn how to use Python for loops to iterate over lists, tuples, strings, and dictionaries with Pythonic looping techniques.
๐ŸŒ
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 - Learn how to leverage Python's range() function for programmatic iteration control in for loops. Master techniques like loop reversal, fixed intervals, and avoiding off-by-one errors.