[Python-ideas] Improve readability of long numeric literals

Manuel Cerón ceronman at gmail.com
Tue Feb 9 16:40:18 EST 2016

Hi everyone!

Sometimes it's hard to read long numbers. For example:

>>> opts.write_buffer_size = 67108864

Some languages (Ruby, Perl, Swift) allow the use of underscores in numeric
literals, which are ignored. They are typically used as thousands
separators. The example above would look like this:

>>> opts.write_buffer_size = 67_108_864

Which helps to quickly identify that this is around 67 million.

Another option is to use spaces instead of underscores:

>>> opts.write_buffer_size = 67 108 864

This has two advantages: 1. is analog to the way string literals work,
which are concatenated if put next to each other. 2. spaces are already
used as thousands separator in many european languages [1].

The disadvantage is that, as far as I known, no other languages do this.

I have seen some old discussions around this, but nothing on this list or a
PEP. With Python being use more and more for scientific and numeric
computation, this is a small change that will help with readability a lot.
And, as far as I can tell, it doesn't break compatibility in any way.



[1] https://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160209/8e20801e/attachment.html>

More information about the Python-ideas mailing list