Is there a function in python that lets me input a number (i.e 3
) and a beginning and end number and steps accordingly:
function (10, 21, 2)
-> [15, 20]
function (0, 16, 5)
-> [3, 6, 9, 12, 15]
Is there a function in python that lets me input a number (i.e 3
) and a beginning and end number and steps accordingly:
function (10, 21, 2)
-> [15, 20]
function (0, 16, 5)
-> [3, 6, 9, 12, 15]
Range is the function which does the same :
for a in range(0,16,3):
print a
Better follow some tutorials these are very basics of python .
If you want to use in a for loop you want - range(<start>,<end>,<Step>)
You can accomplish your task using the range
fucntion. The base syntax is:
range(start, end, step)
range(1, 10, 2) = [1, 3, 5, 7, 9]
range(1, 10, 5) = [1, 6]
More info: http://www.pythoncentral.io/pythons-range-function-explained/