Underscores in Python numbers

Peter Hansen peter at engcorp.com
Sat Nov 19 19:08:57 CET 2005


bearophileHUGS at lycos.com wrote:
> Steven D'Aprano:
>>Perhaps Python should concatenate numeric literals at compile time:
>>123 456 is the same as 123456.
> 
> I think using the underscore it is more explicit:
> n = 123_456
> 
> Alternatively the underscore syntax may be used to separate the number
> from its base:
> 22875 == 22875_10 == 595b_16 == 123456_7
> But probably this is less commonly useful (and not much explicit).

Umm... in other words, "the underscore is under-used so let's assign 
some arbitrary meaning to it" (to make the language more like Perl 
perhaps?).

Or maybe one should instead interpret this as "numeric literals need 
more bells and whistles, and I don't care which of these two we add, but 
we have to do *something*!". :-)

-Peter



More information about the Python-list mailing list