Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!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.096 X-Spam-Evidence: '*H*': 0.83; '*S*': 0.02; 'string': 0.09; 'subject:number': 0.09; '(say': 0.16; 'negative,': 0.16; 'number?': 0.16; 'precision.': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'select': 0.22; 'right.': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'decimal': 0.31; 'not.': 0.33; 'problem': 0.35; 'received:google.com': 0.35; 'method': 0.36; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'most': 0.60; 'first': 0.61; 'jul': 0.74; 'obvious': 0.74; 'counts': 0.83; 'subject:very': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=udyXssMliEv8tCrQoQwjVAIJ79CTk5g24fRP14mPMGU=; b=a4KNCQmfnaJU+1BELMCoOHMRbMXGQfoZ9Cf/2oNjioin5Leb3ZyegduToJSdvxiEoY RAmjQ6s/B0PR97V3Rl6Stbx26IbU/8xY/vFpNGMUYepTR1aroRCB2N1pUI2pVgwKimvo cmVBBcc//ckDsedytm3FLE8Fxa+xm+pL5qaToXr3+/GYe0MBDSd5PuO38JHJjL+sDuEp vShCtv8Dso4zBTWCrM5fZsNu2tQVfnY9GIxt5lKTlb+S74vajdYYHZJuyJjjdwBlepvv zDx8IUZjqAhIR3wwIOggIj7eeduo1K1vpQ7cl5H8fYC24ldyNaD1zwKeFhKNpeui9jxj JlsQ== X-Received: by 10.68.28.232 with SMTP id e8mr8613556pbh.94.1374091876786; Wed, 17 Jul 2013 13:11:16 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <51E6EEC3.50404@lavabit.com> References: <51E6EEC3.50404@lavabit.com> From: Ian Kelly Date: Wed, 17 Jul 2013 14:10:36 -0600 Subject: Re: Storing a very large number To: Python Content-Type: text/plain; charset=ISO-8859-1 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374091886 news.xs4all.nl 15941 [2001:888:2000:d::a6]:60387 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50804 On Wed, Jul 17, 2013 at 1: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? Both the int and Decimal types support arbitrary precision. Floats do not. > And also, how do I select a particular number (say 209th) from that very > large number? You mean a particular digit? The most obvious way is to format it as a string and use indexing. >>> x = 2 ** 1000 >>> str(x)[208] '6' Or using arithmetic: >>> (x // 10 ** 208) % 10 5 Note that the first method counts digits from the left and will be off if the value is negative, while the second method counts digits from the right.