[Python-ideas] Improve readability of long numeric literals

Random832 random832 at fastmail.com
Wed Feb 10 12:42:14 EST 2016


On Tue, Feb 9, 2016, at 18:17, Guido van Rossum wrote:
> Indeed, "123 456" is a no-no, but "123_456" sound good. (Not sure
> about "12_34_56" but there are probably use cases for that too.)

For one, not all languages use the same divisions. In many Indian
languages, the natural divisions would be like 1_23_45_678, whereas in
Chinese and Japanese some people may want to use 1_2345_6789, though the
western system is also common.

Also, dare I suggest, 0x_0123_4567_89AB_CDEF? Arbitrary grouping may be
useful in binary constants representing bit fields.

For that matter, for an integer representing a fixed-point fractional
quantity, one may want to use 1_234_567__0000, where the last separator
represents the decimal place. Mathematical publications sometimes group
digits after a decimal place into groups of five, e.g.
Decimal("3.14159_26535_89793_84626") or combine these ideas for
Fraction(3__14159_26535_89793_84626, 10**20)

I don't know that there's any reason to build restrictions into the
language, any more than to require certain integer constants to be in
decimal and others to be in hexadecimal.


More information about the Python-ideas mailing list