Question

Hi im just wondering what the 4 would do in this code

for y in range(0, height, 4):

Thanks

Was it helpful?

Solution 2

The 4 in the range function used in the for loop indicates the increment step. suppose the value of height is 20. Then the values for y will be set as 0, 0+4=4, 4+4=8, ... till 20 in subsequent iterations of the for loop.

For a more detailed description of range function check out the python documentation at: http://docs.python.org/2/library/functions.html#range

OTHER TIPS

Range with just one parameter: end.

Range with two parameters: start, end.

Range with three parameters: start, end, step.

So in your specific case

 for y in range(0, height, 4)

0, 4, 8, ..., n, where n < height.

plus 4 each time you hit the range. For example,

 for y in range(0, 14, 4)

you will get 0, 4, 8, 12

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top