Underscores in Python numbers

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


On Sun, 20 Nov 2005 01:39:04 +0000, Steve Holden wrote:

> Steven D'Aprano wrote:
> [...]
>> Likewise, base conversion into arbitrary bases is not, in my opinion,
>> common enough a task that support for it needs to be built into the syntax
>> for literals. If somebody cares enough about it, write a module to handle
>> it and try to get it included with the Python standard modules.
>> 
> In fact Icon managed to offer a syntax that allowed every base up to 36 
> to be used: an "r" was used to indicate the radix of the literal, so hex 
> 453FF would be represented as "16r453FF". This worked fine. Upper- and 
> lower-case letters werw regarded as equivalent.

Forth goes significantly further than that: you can tell the Forth
interpreter what base you are using, and all numbers are then read and
displayed using that base. Numbers were case sensitive, which meant Forth
understood bases to at least 62. I don't remember whether it allows
non-alphanumeric digits, and therefore higher bases -- I think it does,
but am not sure.

Nevertheless, I don't believe that sort of functionality belongs in the
language itself. It is all well and good to be able to write 32r37gm, but
how often do you really need to write numbers in base 32?



-- 
Steven.




More information about the Python-list mailing list