[Python-Dev] PEP 515: Underscores in Numeric Literals
Steven D'Aprano
steve at pearwood.info
Thu Feb 11 05:29:48 EST 2016
On Thu, Feb 11, 2016 at 08:07:56PM +1000, Nick Coghlan wrote:
> Given that str.format supports a thousands separator:
>
> >>> "{:,d}".format(100000000)
> '100,000,000'
>
> it might be reasonable to permit "_" in place of "," in the format specifier.
+1
> However, I'm not sure when you'd use it aside from code generation,
> and you can already insert the thousands separator and then replace
> "," with "_".
It's not always easy or convenient to call .replace(",", "_") on the
output of format:
"With my help, the {} caught {:,d} ants.".format("aardvark", 100000000)
would need to be re-written as something like:
py> "With my help, the {} caught {} ants.".format("aardvark",
"{:,d}".format(100000000).replace(",", "_"))
'With my help, the aardvark caught 100_000_000 ants.'
--
Steve
More information about the Python-Dev
mailing list