[Python-ideas] User-defined literals
njs at pobox.com
Tue Jun 2 23:26:22 CEST 2015
On Jun 2, 2015 1:32 PM, "Chris Kaynor" <ckaynor at zindagigames.com> wrote:
> On Tue, Jun 2, 2015 at 12:40 PM, Nathaniel Smith <njs at pobox.com> wrote:
>> Are there any use cases besides decimals? Wouldn't it be easier to
>> just add, say, a fixed "0d" prefix for decimals?
>> 0x1001 # hex
>> 0b1001 # binary
>> 0d1.001 # decimal
> In terms of other included useful options, you also have fractions.
> There could also be benefit of using such a system for cases of numbers
with units, such as having the language understand 23.49MB.
The unit libraries I've seen just spell this as "23.49 * MB" (or "22.49 *
km / h" for a speed, say). And crucially they don't have any need to
override the parsing rules for float literals.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas