Is there any method like divide by or multiply by in python range()?
问题 for java, we can do: for(int i=100; i>2 ; i=i/2){things to execute} but what if in python? is there anything like for i in range(100:2:something) could solve this problem? 回答1: If you need something simple which you can have at hand at several places, you can create a generator function: def range_divide(start, end, denominator): # TODO: Think for a better name! value = start while value > end: yield value value /= denominator and then do for value in range_divide(100, 2, 2): # do_stuff You