久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Python 中管理大量數字的除法?

How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
本文介紹了如何在 Python 中管理大量數字的除法?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 100 位數字,我試圖將數字的所有數字放入一個列表中,以便對它們執行操作.為此,我使用以下代碼:

I have a 100 digit number and I am trying to put all the digits of the number into a list, so that I can perform operations on them. To do this, I am using the following code:

for x in range (0, 1000):
   list[x] = number % 10
   number = number / 10

但我面臨的問題是我收到了一個溢出錯誤,比如浮點數/整數太大.我什至嘗試使用以下替代方法

But the problem I am facing is that I am getting an overflow error something like too large number float/integer. I even tried using following alternative

number = int (number / 10)

如何將這個巨大的數字除以整數類型的結果,即沒有浮點數?

How can I divide this huge number with the result back in integer type, that is no floats?

推薦答案

在 Python 3 中,number/10 將嘗試返回 float.但是,浮點值在 Python 中不能任意大,如果 number 很大,則會引發 OverflowError.

In Python 3, number / 10 will try to return a float. However, floating point values can't be of arbitrarily large size in Python and if number is large an OverflowError will be raised.

您可以使用 sys 模塊找到 Python 浮點值可以在您的系統上使用的最大值:

You can find the maximum that Python floating point values can take on your system using the sys module:

>>> import sys
>>> sys.float_info.max
1.7976931348623157e+308

要繞過此限制,請改為使用 // 從兩個整數的除法中取回一個整數:

To get around this limitation, instead use // to get an integer back from the division of the two integers:

number // 10

這將返回 number/10int 底值(它不會產生浮點數).與浮點數不同,int 值可以根據您在 Python 3 中所需的大小(在內存限制內).

This will return the int floor value of number / 10 (it does not produce a float). Unlike floats, int values can be as large as you need them to be in Python 3 (within memory limits).

您現在可以劃分大數.例如,在 Python 3 中:

You can now divide the large numbers. For instance, in Python 3:

>>> 2**3000 / 10
OverflowError: integer division result too large for a float

>>> 2**3000 // 10
123023192216111717693155881327...

這篇關于如何在 Python 中管理大量數字的除法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits(用于確定兩個數字在舍入到 n 個有效十進制數字時是否幾乎相等的函數)
主站蜘蛛池模板: 日本午夜精品一区二区三区 | 欧美成人一区二区三区片免费 | 久久久久精 | 美女毛片| 国产精品欧美一区二区三区 | 2018天天干天天操 | 尤物在线精品视频 | 日韩精品成人av | 成人国产精品免费观看 | 成人欧美一区二区三区在线播放 | 国产一级片一区二区三区 | 精品久久久久久久久久久久久久 | 成人一区二区三区 | 国产精品欧美一区二区三区不卡 | 亚洲一区二区三区视频在线 | 国产精品视频免费观看 | 国产精品视频一区二区三区不卡 | 欧美日韩成人影院 | 一级日韩 | 九九色综合 | 久久美国 | 国产电影一区二区在线观看 | 久久日韩粉嫩一区二区三区 | 日韩欧美国产精品 | 久久亚洲国产 | 欧美一区二区在线观看视频 | 欧美激情在线精品一区二区三区 | 久久久久久综合 | 成人免费观看男女羞羞视频 | 免费观看一级特黄欧美大片 | 九九免费 | 福利久久| 日日摸日日碰夜夜爽亚洲精品蜜乳 | 成人av免费在线观看 | 国产一区久久精品 | 婷婷丁香在线视频 | 亚洲欧洲视频 | 亚洲成人免费视频 | 精品一区二区三区免费视频 | 天天操 夜夜操 | 91精品一区二区三区久久久久久 |