l = range(int(1E9))
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri May 1 00:42:04 EDT 2015
On Fri, 1 May 2015 02:06 am, Cecil Westerhof wrote:
> If I execute:
> l = range(int(1E9)
Others have already answered your questions about memory. Let me answer the
question you didn't ask about style :-)
Don't use "l" as a variable name, as it looks too much like 1. Better to use
L, or even better, a meaningful name.
Rather than convert a float 1E9 to an int at runtime, better to use an int:
range(10**9)
With recent versions of CPython, the compiler has a keyhole optimiser which
does constant folding. For implementations of Python which don't do
constant folding, 10**9 is likely to be faster than int(1E9) -- but even if
it isn't, does it matter? It will be very fast one way of the other. The
important thing is that 10**9 expresses the intention to use an integer in
a more direct fashion than using 1E9.
--
Steven
More information about the Python-list
mailing list