[Tutor] A Million Sevens

Thomas tavspam at gmail.com
Sat Nov 18 03:38:25 CET 2006


On 18/11/06, Chris Hengge <pyro9219 at gmail.com> wrote:
> Not that it changes your reply, but just for my own sanity:
> int('7' * 10 ** 6) <- does this not just type-cast a char into an int?
>
> Meaning that rather then consuming 1024k as you stated, it would consume 2048k at the peak of the calculation(2bytes per char? * 1m = 2048k) then typecasting to int would drop it back down to 1k (1byte per int * 1m = 1024k
>
> So, just for sake of getting to a point since I missed the one by the original poster.. why would you not convert that 7 from a char to an int first? That calculation is almost instant, and it doesn't require the memory rollercoaster that this calculation would require..
>
> Anyways.. back to the poster...

Thanks, original poster here, I was just reading my new book, Core
Python Programming (2nd Edition) and it said that there was no
in-built limit to the size of a long in python (as compared to C) so I
wanted to test it out. I just typed the first way of getting a massive
number that came into my head.

> Perhaps you wanted an error like this?
>
> print '=' * 1000000000
> Traceback (most recent call last):
>   File "<input>", line 1, in ?
> MemoryError

Now that is exactly what I thought I might get. I'll try it again with
some of the variations mentioned on Monday when I get back to that
computer.


More information about the Tutor mailing list