0

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

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

Thanks

user2194374
  • 123
  • 3
  • 4
  • 9

3 Answers3

3

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.

Artur K.
  • 3,263
  • 3
  • 38
  • 54
1

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

DotPi
  • 3,977
  • 6
  • 33
  • 53
  • the 4 is a value in the "range" call - and both are not _part_ of Python's `for` statement - you could clarify that. – jsbueno Mar 23 '13 at 10:56
  • That is why I had included the python documentation for range. I will edit the answer to reflect it better. – DotPi Mar 23 '13 at 12:43
1

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

 for y in range(0, 14, 4)

you will get 0, 4, 8, 12

Yarkee
  • 9,086
  • 5
  • 28
  • 29