What does the underscore mean in literal numbers?

后端 未结 4 539
孤独总比滥情好
孤独总比滥情好 2020-12-29 01:22

What does that mean?
0.0..10_000.0

4条回答
  •  庸人自扰
    2020-12-29 01:56

    It is a Range object, of the kind a..b

    In this case it gives you the numbers from 0 to 10,000 as Floats.

    the underscore '_' is ignored, and used for readability, so 10_000 is equivalent 10,000.

    Buy adding .0 to each part of the range, the numbers would be considered as floats instead of integers, so you won't be able to iterate over the range (the each method would raise an exception).

提交回复
热议问题