[Python-Dev] PEP 515: Underscores in Numeric Literals (original) (raw)

Georg Brandl g.brandl at gmx.net
Thu Feb 11 02:45:30 EST 2016


On 02/10/2016 11:35 PM, Brett Cannon wrote:

Examples::

# grouping decimal numbers by thousands amount = 10000000.0 # grouping hexadecimal addresses by words addr = 0xDEADBEEF # grouping bits into bytes in a binary literal flags = 0b0011111101001110 I assume all of these examples are possible in either the liberal or restrictive approaches?

The last one isn't for restrictive -- its first underscore isn't between digits.

Implementation ============== A preliminary patch that implements the specification given above has been posted to the issue tracker. [11] Is the implementation made easier or harder if we went with the Group 2 or 3 approaches? Are there any reasonable examples that the Group 1 approach allows that Group 3 doesn't that people have used in other languages?

Group 3 is probably a little more work than group 2, since you have to make sure only one consecutive underscore is present. I don't see a point to that.

I'm +1 on the idea, but which approach I prefer is going to be partially dependent on the difficulty of implementing (else I say Group 3 to make it easier to explain the rules).

Based on the feedback so far, I have an easier rule in mind that I will base the next PEP revision on. It's basically

"One ore more underscores allowed anywhere after a digit or a base specifier."

This preserves my preferred non-restrictive cases (0b_1111_0000, 1.5_j) and disallows more controversial versions like "1.5e_+_2".

cheers, Georg



More information about the Python-Dev mailing list