[Python-ideas] Improve readability of long numeric literals

Georg Brandl g.brandl at gmx.net
Wed Feb 10 13:10:38 EST 2016


On 02/10/2016 07:00 PM, Random832 wrote:
> On Wed, Feb 10, 2016, at 12:51, Georg Brandl wrote:
>> 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)
> 
> I don't think it's particularly important to support this case, but the
> sequence digit/dot/name with no spaces between is a syntax error now,
> because the digit/dot is interpreted as a floating point constant.

Don't forget that float literals can also start with just the dot.  Therefore
this case can get quite ambiguous.

expr  ._2        is an attribute access
expr 0._2        is a syntax error

>> * directly after a sign in exponents (for consistency with leading signs)
>> * in the middle of the "0x", "0o" or "0b" base specifiers
> 
> Do you allow multiple underscores in a row? I mentioned a couple
> possible use cases for that.

Yes, there is no restriction.

Georg




More information about the Python-ideas mailing list