Storing a very large number
ian.g.kelly at gmail.com
Wed Jul 17 22:10:36 CEST 2013
On Wed, Jul 17, 2013 at 1:21 PM, Hasit Mistry <hasitnm at lavabit.com> 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
Or using arithmetic:
>>> (x // 10 ** 208) % 10
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
More information about the Python-list