[Tutor] for loop for long numbers

Alan Gauld alan.gauld at btinternet.com
Mon Aug 3 22:56:59 CEST 2015

On 03/08/15 19:15, Dima Kulik wrote:

> I want to make a for loop with a huge numbers.
> for example:
> for i in range (0,9000000000):
>   make_some_code
> but range and xrange cant operate with such big numbers.

What makes you think so? Did you try? What error did you get?
And what version of python were you using?

FWIW I tried xrange with 10**16 and it seemed to work,
albeit it took a long time.(about 15min for each 10**10
iterations)) I gave up waiting after it reached 10**11...

But if you are sure that doesn't work you can always use
a while loop instead:

n = 0
while n < 10**15
    # do something
    n += 1

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list