Changing step in Python loop -
in python 2.7 want modify step of for loop in function of specifics conditions satisfied in loop. this:
step = 1 in range(1, 100, step): if ...... : step = 1 #do stuff else: step = 2 #do other stuff but seems can't done, step 1.
thanks.
you need increment step manually can done using while loop. checkout difference between while , for loop.
the statement iterates through collection or iterable object or generator function.
the while statement loops until condition false.
if use while loop code this:
step = 1 = 1 while < 100: if ...... : step = 1 #do stuff else: step = 2 #do other stuff = + step
Comments
Post a Comment