Underscores in Python numbers

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Nov 19 00:56:54 EST 2005


On Fri, 18 Nov 2005 16:26:08 -0800, bonono at gmail.com wrote:

> Personally, I would rather see the int() and float() function be
> smarter to take what is used for this, i.e. :
> 
> a = int("1,234,567")

But the problem isn't just with conversion of strings. It is also
with literals.

n = 99999999999

Without counting, how many nines?

Obviously repeated digits is an extreme case, but even different digits
are easier to process if grouped. That's why we write phone numbers like
62 3 9621 2377 instead of 62396212377.

Here is a thought: Python already concatenates string literals:

"abc" "def" is the same as "abcdef".

Perhaps Python should concatenate numeric literals at compile time:

123 456 is the same as 123456.

Off the top of my head, I don't think this should break any older code,
because 123 456 is not currently legal in Python.


-- 
Steven.




More information about the Python-list mailing list