[Python-ideas] Improve readability of long numeric literals
Georg Brandl
g.brandl at gmx.net
Wed Feb 10 12:51:02 EST 2016
On 02/09/2016 10:40 PM, Manuel CerĂ³n wrote:
> 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.
> Thoughts?
I like it, and for everybody to try it out, I posted a draft patch here:
http://bugs.python.org/issue26331
Underscores are allowed anywhere in numeric literals, except:
* at the beginning of a literal (obviously)
* at the end of a literal
* directly after a dot (since the underscore could start an attribute name)
* directly after a sign in exponents (for consistency with leading signs)
* in the middle of the "0x", "0o" or "0b" base specifiers
Reviewers welcome!
cheers,
Georg
More information about the Python-ideas
mailing list