[Tutor] range() or xrange() for non-integers?
Bob Gailer
bgailer at alum.rpi.edu
Sat Sep 13 13:36:01 EDT 2003
At 11:33 AM 9/13/2003, Terry Carroll wrote:
>I found myself needing something like this:
>
> for x in xrange(-4.0, 4.0, 0.5):
> print x
>
>(The print line will, of course, in practice, be something more useful.)
>
>
>I found that xrange (and range) do not work except with integers.
>
>What's the pythonic way to do this, under 2.2?
Probably several ways. One is:
from __future__ import division
for x in xrange(-8.0, 8.0, 1.0):
print x/2
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003
More information about the Tutor
mailing list