[Python-ideas] 1_000_000
Bruce Leban
bruce at leapyear.org
Fri May 6 23:38:19 CEST 2011
None of these answers address the original suggestion. Matt didn't say that
he only wanted this for numbers of the form 10^N; he just gave that as an
example.
Consider these examples instead:
- 1_234_000
- 9.876_543_210
- 0xFEFF_0042
I'm not advocating this change (nor against it); I just think the discussion
should be focused on the actual idea. I do have a question:
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?)
--- Bruce
Puzzazz newsletter: http://j.mp/puzzazz-news-2011-04 including April Fools!
Blog post: http://www.vroospeak.com Ironically, a glaring Google grammatical
error
On Fri, May 6, 2011 at 2:26 PM, Kirubakaran <kirubakaran at gmail.com> wrote:
> (fixed typo)
> How about range(10**6) ?
>
> - Kirubakaran.
>
>
> On Fri, May 6, 2011 at 2:25 PM, Kirubakaran <kirubakaran at gmail.com> wrote:
>
>> How about range(10**60) ?
>>
>> - Kirubakaran.
>>
>>
>> On Fri, May 6, 2011 at 2:24 PM, Antoine Pitrou <solipsis at pitrou.net>wrote:
>>
>>> On Fri, 6 May 2011 23:06:18 +0200
>>> "dag.odenhall at gmail.com"
>>> <dag.odenhall at gmail.com> wrote:
>>> > On 6 May 2011 19:51, Matt Chaput <
>>> matt-KKMwxO2wslj3fQ9qLvQP4Q at public.gmane.org> wrote:
>>> > > Not sure if this has been proposed before: A syntax change to allow
>>> > > underscores as thousands separators in literal numbers to improve
>>> > > readability, e.g.:
>>> > >
>>> > > for i in range(1, 1_000_000):
>>> > > pass
>>> > >
>>> > > I believe D allows this and while it's a small thing it really is
>>> much more
>>> > > readable.
>>> >
>>> > Ruby too.
>>> >
>>> > You could also use e-notation[1]: 1e6, in your example. In many
>>> > situations it's even more readable because you don't need to "count
>>> > the zeros". This is already supported in Python.
>>>
>>> Yes, but it gives a float, not an integer:
>>>
>>> >>> for i in range(0, 1e6): pass
>>> ...
>>> Traceback (most recent call last):
>>> File "<stdin>", line 1, in <module>
>>> TypeError: 'float' object cannot be interpreted as an integer
>>>
>>>
>>> Regards
>>>
>>> Antoine.
>>>
>>>
>>> _______________________________________________
>>> Python-ideas mailing list
>>> Python-ideas at python.org
>>> http://mail.python.org/mailman/listinfo/python-ideas
>>>
>>
>>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110506/e21708a8/attachment.html>
More information about the Python-ideas
mailing list