Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!border1.nntp.ams2.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder3.cambriumusenet.nl!feed.tweaknews.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'python.': 0.02; 'string': 0.09; 'subject:number': 0.09; 'python': 0.11; 'assume': 0.14; '(say': 0.16; 'character:': 0.16; 'notifies': 0.16; 'number?': 0.16; 'index': 0.16; 'wrote:': 0.18; 'advance.': 0.19; '>>>': 0.22; 'select': 0.22; 'header:User-Agent:1': 0.23; 'header:In- Reply-To:1': 0.27; 'gary': 0.31; 'ok.': 0.31; "i'd": 0.34; 'problem': 0.35; "can't": 0.35; 'but': 0.35; 'received:10': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'number,': 0.60; 'new': 0.61; 'numbers': 0.61; 'relatively': 0.65; 'institute': 0.72; 'received:10.10': 0.74; 'received:204': 0.75; 'dr.': 0.77; 'subject:very': 0.91 Date: Wed, 17 Jul 2013 13:02:25 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Storing a very large number References: <51E6EEC3.50404@lavabit.com> In-Reply-To: <51E6EEC3.50404@lavabit.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 35 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374091807 news.xs4all.nl 15925 [2001:888:2000:d::a6]:59516 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50803 On 07/17/2013 12:21 PM, Hasit Mistry wrote: > I came across a problem that requires me to store a very large number > (say >10^100). How do I do it efficiently? > And also, how do I select a particular number (say 209th) from that > very large number? > I am relatively new to Python. > > Thank you in advance. > Python already has long numbers (integers) built in.: >>> 10**100 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L The 'L' on the end notifies you it's a *long* int. I can't speak about its efficiency, but I assume it's OK. By 209th number, do you mean 209th *digit*? I'd say just get a string representation and index the 209th character: >>> str(12**345) '2077446682327378559843444695582704973572786912705232236931705903179519704325276892191015329301807037794598378537132233994613616420526484930777273718077112370160566492728059713895917217042738578562985773221381211423961068296308572143393854703167926779929682604844469621152130457090778409728703018428147734622401526422774317612081074841839507864189781700150115308454681772032' >>> str(12**345)[209] '1' Gary Herron -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418