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

Terry Reedy tjreedy at udel.edu
Thu Feb 11 12:39:07 EST 2016


On 2/11/2016 2:45 AM, Georg Brandl wrote:

Thanks for grabbing this issue and moving it forward. I will like being about to write or read 200_000_000 and be sure I an right without counting 0s.

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 (0b11110000, 1.5j) and disallows more controversial versions like "1.5e+2".

I like both choices above. I don't like trailing underscores for two reasons.

  1. The stated purpose of adding '_'s is to visually separate. Trailing underscores do not do that. They serve no purpose.
  2. Trailing s are used to turn keywords (class) into identifiers (class). To me, 123_ mentally clashes with this usage.

If trailing _ is allowed, to simplify the implementation, I would like PEP 8, while on the subject, to say something like "While trailing _s on numbers are allowed, to simplify the implementation, they serve no purpose and are strongly discouraged".

-- Terry Jan Reedy



More information about the Python-Dev mailing list