Is there a range() equivalent for floats in Python?
>>> range(0.5,5,1.5)
[0, 1, 2, 3, 4]
>>> range(0.5,5,0.5)
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
range(0.5,5,0.5)
ValueError: range() step argument must not be zero
I don’t know a built-in function, but writing one like [this](https://stackoverflow.com/a/477610/623735) shouldn’t be too complicated.
—
As the comments mention, this could produce unpredictable results like:
To get the expected result, you can use one of the other answers in this question, or as @Tadhg mentioned, you can use
decimal.Decimalas thejumpargument. Make sure to initialize it with a string rather than a float.Or even:
And then:
[editor’s not: if you only use positive
jumpand integer start and stop (xandy) , this works fine. For a more general solution see here.]