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

Python 3 中的 int() 和 floor() 有什么區別?

What is the difference between int() and floor() in Python 3?(Python 3 中的 int() 和 floor() 有什么區別?)
本文介紹了Python 3 中的 int() 和 floor() 有什么區別?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在 Python 2 中,floor() 返回一個浮點值.雖然對我來說不是很明顯,但我找到了一些解釋,闡明了為什么讓 floor() 返回浮點數可能有用(對于像 float('inf') 和 <代碼>浮動('nan')).

In Python 2, floor() returned a float value. Although not obvious to me, I found a few explanations clarifying why it may be useful to have floor() return float (for cases like float('inf') and float('nan')).

然而,在 Python 3 中,floor() 返回整數(并且對于前面提到的特殊情況返回溢出錯誤).

However, in Python 3, floor() returns integer (and returns overflow error for the special cases mentioned before).

那么 int()floor() 現在有什么區別?

So what is the difference, if any, between int() and floor() now?

推薦答案

floor() 循環 down.int() 截斷.使用負數時區別很明顯:

floor() rounds down. int() truncates. The difference is clear when you use negative numbers:

>>> import math
>>> math.floor(-3.5)
-4
>>> int(-3.5)
-3

對負數進行四舍五入意味著它們遠離 0,截斷使它們更接近 0.

Rounding down on negative numbers means that they move away from 0, truncating moves them closer to 0.

換句話說,floor() 總是會低于或等于原始值.int() 將接近于零或等于.

Putting it differently, the floor() is always going to be lower or equal to the original. int() is going to be closer to zero or equal.

這篇關于Python 3 中的 int() 和 floor() 有什么區別?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 欧美一区二区三区在线视频 | 夜夜操天天操 | 中文字幕免费在线观看 | 亚洲在线一区二区 | 日韩精品久久久 | 色婷婷成人| 日韩精品视频免费播放 | 午夜免费福利视频 | 触手繁殖の地狱3d啪啪 | 国产成人97精品免费看片 | 国产精品一区三区 | 日韩免费高清视频 | 国产欧美精品一区二区 | 亚洲欧美日本在线 | 伦一理一级一a一片 | av手机天堂 | 午夜综合网 | 五月婷婷六月天 | 亚洲国产激情 | 蜜桃精品一区二区 | 亚洲精品免费在线观看 | 国产成人黄色 | 久久98| 国产成人在线观看免费网站 | av大全在线观看 | 少妇免费视频 | 亚洲视频一区 | 麻豆成人91精品二区三区 | 放几个免费的毛片出来看 | 久久久久久久九九九九 | 日本免费毛片 | 成人小视频在线 | 一区二区国产精品 | 国产精品毛片va一区二区三区 | 久久精品在线 | 中文字幕免费 | 在线观看免费毛片 | 免费看成人片 | 天堂av在线资源 | 香蕉视频色版 | 日韩中文字幕第一页 |