Re: Underscores in Python numbers
Steven D'Aprano:[color=blue]
> Perhaps Python should concatenate numeric literals at compile time:
> 123 456 is the same as 123456.[/color]
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).
Bye,
bearophile
Steven D'Aprano:[color=blue]
> Perhaps Python should concatenate numeric literals at compile time:
> 123 456 is the same as 123456.[/color]
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).
Bye,
bearophile
Comment