To loop in steps of two in python, use the range()
function with a step parameter. The range()
function generates a sequence of numbers, and the third parameter determines the step size. By default, the step size is 1. Here's an example:
main.py39 chars3 lines
In this example, the range()
function generates a sequence of numbers from 0 to 9 with a step size of 2. The loop then iterates through each number in the sequence and prints it to the console. The output will be:
main.py10 chars6 lines
In this way, you can easily loop in steps of two in python by using the range()
function with a step parameter.
gistlibby LogSnag