[Python-ideas] 1_000_000
MRAB
python at mrabarnett.plus.com
Sat May 7 01:41:33 CEST 2011
On 06/05/2011 23:51, Cameron Simpson wrote:
> On 06May2011 15:40, Ethan Furman<ethan at stoneleaf.us> wrote:
> | Bruce Leban wrote:
> |>Is _ just ignored in numbers or are there more complex rules?
> |>
> |> * 1_2345_6789 (can I use groups of other sizes instead?)
> |> * 1_2_3_4_5 (ditto)
> |> * 1_234_6789 (do all the groups need to be the same size?)
> |> * 1_ (must the _ only be in between 2 digits?)
> |> * 1__234 (what about multiple _s?)
> |> * 9.876_543_210 (can it be used to the right of the decimal point?)
> |> * 0xFEFF_0042 (can it be used in hex, octal or binary numbers?)
> |> * int('123_456') (do other functions accept this syntax too?)
> |
> | I would say it's ignored. Have the rule be something like
> | number_string.replace('_','').
> |
> | The only wrinkle is that currently '_1' is usable name, and that
> | should probably be disallowed if the above change took place.
> |
> | I'm +1 on the idea.
>
> Personally I'm be for ignoring the _ also, save that I would forbid it
> at the start or end, so no _1 or 1_.
>
> And I would permit it in hex code etc.
>
> I'm +0.5, myself.
>
As far as I remember, Ada also permits it, but has the rule that it can
occur only between digits. If we follow that, then:
1_2345_6789 => Yes
1_2_3_4_5 => Yes
1_234_6789 => Yes
1_ => No
_1 => No
1__234 => No
9.876_543_210 => Yes
9._876_543_210 => No
9_.876_543_210 => No
0xFEFF_0042 => Yes
int('123_456') => Yes
More information about the Python-ideas
mailing list