Saturday, June 11, 2016

python for loop and range: variable on loop line is not reinitialized

for y in range(x, 10):
...     print y
...     x += 1

In the above example the range does not change even if value of x is changing

but the range will change in the example below

for x in range(0, 4):
    for y in range(4, x, -1):
        print y

No comments:

Post a Comment