You can use a range with a step size of 2:

Python 2

for i in xrange(0,10,2):
  print(i)

Python 3

for i in range(0,10,2):
  print(i)

Note: Use xrange in Python 2 instead of range because it is more efficient as it generates an iterable object, and not the whole list.

Answer from Brian R. Bondy 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).
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-for-loops
Python For Loops - GeeksforGeeks
Python continue Statement returns the control to the beginning of the loop. ... # Prints all letters except 'e' and 's' for i in 'geeksforgeeks': if i == 'e' or i == 's': continue print(i)
Published ย  1 week ago
๐ŸŒ
Coursera
coursera.org โ€บ tutorials โ€บ for-loop-python
How to Use For Loops in Python: Step by Step | Coursera
February 24, 2023 - ... Write the iterator variable (or loop variable). The iterator takes on each value in an iterable (for example a list, tuple, or range) in a for loop one at a time during each iteration of the loop.
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ python โ€บ python-for-loop โ€บ python-for-loop-increment-step
Python For Loop Increment in Steps
July 22, 2021 - ... step = int(input('Enter step value : ')) list_1 = [9, 5, 7, 2, 5, 3, 8, 14, 6, 11] for i in range(0, len(list_1), step) : print(list_1[i]) ... In this Python Tutorial, we learned how to use for loop with range() function, to loop through ...
๐ŸŒ
Programink
programink.com โ€บ python-tutorial โ€บ for-loop-in-python.html
For Loop In Python
March 30, 2021 - A for loop in python is used to iterable over sequences or collections. It can be programmed to go primarily over index or value. It uses an iterating variable that iterates over the next value from the iterable collection or range() function. range() function makes an iterable object with the given start point, endpoint, and step of traversal.
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ ForLoop
ForLoop - Python Wiki
For loop from 0 to 2, therefore running 3 times. for x in range(0, 3): print("We're on time %d" % (x))
Find elsewhere
๐ŸŒ
Serverspace
serverspace.io โ€บ support โ€บ help โ€บ for-loop-python
Python 3 For Loop Explained: Syntax and Practical Examples
June 1, 2025 - One of the built-in sequences is ... sequence (optional parameter and default value 0) ... Step โ€“ is a sequence step (optional parameter and default value 1)....
๐ŸŒ
Snakify
snakify.org โ€บ for loop with range
For loop with range - Learn Python 3 - Snakify
Pay attention that maximum value in range() is n + 1 to make i equal to n on the last step. 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 ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ how to increment for loop in python
How to Increment For Loop in Python - Spark By {Examples}
May 31, 2024 - step(optional) โ€“ The increment between each number in the sequence. If not specified, it defaults to 1. Specifies how to increment the value. ... Python range() function is used to generate a sequence of numbers within a given range.
๐ŸŒ
Tutorjoes
tutorjoes.in โ€บ python_programming_tutorial โ€บ for_loop_in_python
For Loop in Python
June 27, 2024 - This program is a Python script that demonstrates the use of the for loop and the built-in ... range() function to create an iterator that generates a sequence of numbers from 0 (inclusive) to 21 (exclusive) with a step of 2.
๐ŸŒ
Renan Moura
renanmf.com โ€บ inรญcio โ€บ python for loop increment by 2
Python for loop increment by 2 - Renan Moura
April 16, 2023 - In this case Iโ€™m starting on index 1, which is the number 2 in the list, remember lists are 0-indexed in Python. I wonโ€™t put any stop value since I want to go until the last index. Finally, I put a step of 2. numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] for i in numbers[1::2]: print(i)
๐ŸŒ
OpenStax
openstax.org โ€บ books โ€บ introduction-python-programming โ€บ pages โ€บ 5-2-for-loop
5.2 For loop - Introduction to Python Programming | OpenStax
March 13, 2024 - The range() function is a common approach for implementing counting in a for loop. 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.
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ how-to-change-step-in-for-loop-python
Mastering the Step Parameter in Python's For Loops - CodeRivers
February 14, 2026 - Fundamental Concepts of Changing Step in a For Loop ... The range() function in Python is often used in for loops to generate a sequence of numbers. The basic syntax of the range() function is range(start, stop, step). - start (optional): The starting value of the sequence.
๐ŸŒ
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu โ€บ notebooks โ€บ chapter05.01-For-Loops.html
For-Loops โ€” Python Numerical Methods
The Python function sum has already been written to handle the previous example. However, assume you wish to add only the even numbers. What would you change to the previous for-loop block to handle this restriction? s = 0 for i in range(0, len(a), 2): s += a[i] print(s) ... NOTE! We use step as 2 in the range function to get the even indexes for list a.
๐ŸŒ
University of Pittsburgh
sites.pitt.edu โ€บ ~naraehan โ€บ python3 โ€บ mbb14.html
Python 3 Notes: for Loops
November 8, 2023 - Python 3 Notes [ HOME | LING 1330/2330 ] Tutorial 14: for Loops << Previous Tutorial Next Tutorial >> On this page: using a for loop. Video Tutorial Python 3 Changes print(x,y) instead of print x, y Python 2 vs. 3 Summary ยท Video Summary Loops are a way to repeat a set of actions a specific ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-for-loop-example
Python for loop | DigitalOcean
March 14, 2024 - When you want the for loop to run for a specific number of times, or you need to specify a range of objects to print out, the range function works really well. When working with range(), you can pass between 1 and 3 integer arguments to it: start states the integer value at which the sequence begins, if this is not included then start begins at 0 ยท stop is always required and is the integer that is counted up to but not included ยท step sets how much to increase (or decrease in the case of negative numbers) the next iteration, if this is omitted then step defaults to 1
๐ŸŒ
Python Course
python-course.eu โ€บ python-tutorial โ€บ for-loops.php
20. For Loops | Python Tutorial | python-course.eu
The Python for loop starts with the keyword "for" followed by an arbitrary variable name, which will hold the values of the following sequence object, which is stepped through. The general syntax looks like this: for <variable> in <sequence>: <statements> else: <statements>