Programming Question

Charles G Waldman cgw at fnal.gov
Tue Sep 21 12:30:23 EDT 1999


Richard van de Stadt writes:

 > This does what you want:
 > >>> for i in range(-40, 40, 1.0):
 > >>>	print i/10.0
 > 
 > I don't know why this doesn't work:
 > >>> for i in range(-4, 4, .1):
 > >>>	print i
 > 
 > Traceback (innermost last):
 >   File "<stdin>", line 1, in ?
 > ValueError: zero step for range()

Because "range" takes integer arguments only, and if you pass
non-integer arguments they will be coerced to integers.  Now why
"range()" was designed to work this way is another question
entirely...





More information about the Python-list mailing list