Proposal: Decimal literals in Python.
python at mrabarnett.plus.com
Tue Jul 14 11:55:18 EDT 2009
Scott David Daniels wrote:
> Tim Roberts wrote:
>> My favorite notation for this comes from Ada, which allows arbitrary
>> from 2 to 16, and allows for underscores within numeric literals:
>> x23_bin : constant := 2#0001_0111#;
>> x23_oct : constant := 8#27#;
>> x23_dec : constant := 10#23#;
>> x23_hex : constant := 16#17#;
> And mine is one w/o the base 10 bias:
> .f.123 == 0x123
> .7.123 == 0o123
> .1.1101 == 0b1101
> That is, .<largest allowed digit>.<digits>
> -- show the base by showing base-1 in the base.
> I actually built this into "OZ," an interpretter.
Smalltalk uses "r" (for "radix"). If we also permit underscores:
x23_bin = 2r0001_0111
x23_oct = 8r27
x23_dec = 10r23
x23_hex = 16r17
More information about the Python-list