Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder04.ams.xsnews.nl!abp002.ams.xsnews.nl!frontend-F09-05.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.python Subject: Re: l = range(int(1E9)) Organization: Decebal Computing References: <87k2wtvbx1.fsf@Equus.decebal.nl> <5543041d$0$12996$c3e8da3$5496439d@news.astraweb.com> X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Fri, 01 May 2015 07:13:43 +0200 Message-ID: <87y4l8ribc.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:5UK9rjEwtgltgJEVSzYBEvK+uTI= MIME-Version: 1.0 Content-Type: text/plain Lines: 38 NNTP-Posting-Host: 81.207.62.244 X-Trace: 1430457291 news.kpn.nl 19737 81.207.62.244@kpn/81.207.62.244:42692 Xref: csiph.com comp.lang.python:89694 Op Friday 1 May 2015 06:42 CEST schreef Steven D'Aprano: > 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 :-) That can be very useful. > 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. It was just a short hack to show the problem. In real code I would never use l. But I'll remember to use 10**9 instead of 1E9. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof