[issue41719] Why does not range() support decimals?

Steven D'Aprano report at bugs.python.org
Fri Sep 4 21:11:01 EDT 2020


Steven D'Aprano <steve+python at pearwood.info> added the comment:

Generating a range of equally-spaced floats is tricky and the range builtin is not the right solution for this.

For numerical work, we often need to specify the number of steps, not the step size. For instance, in numeric integration, we often like to double the number of steps and avoid re-calculation.

We often need to skip either the start or end point, or both, or neither.

If you specify the step size, as range does, you can have off-by-one errors due to float rounding.

See here for a discussion and possible solution:

https://code.activestate.com/recipes/577878

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41719>
_______________________________________


More information about the Python-bugs-list mailing list