Loop with float increments (frange)?

Diez B. Roggisch deets at nospam.web.de
Fri Apr 14 10:40:22 EDT 2006


forum at anton.e4ward.com wrote:

> Hi!
> 
> what's the standard way for a "for" loop with float increments?

AFAIK there is no, but you should be easily able to write an frange
yourself:


def frange(from, to, step):
    while from < to:
       yield from
       from += step

for x in frange(10.5, 23.4, 0.3):
   print x


Diez



More information about the Python-list mailing list