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

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

What is the difference between int() and floor() in Python 3?(Python 3 中的 int() 和 floor() 有什么區(qū)別?)
本文介紹了Python 3 中的 int() 和 floor() 有什么區(qū)別?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

在 Python 2 中,floor() 返回一個(gè)浮點(diǎn)值.雖然對(duì)我來(lái)說(shuō)不是很明顯,但我找到了一些解釋?zhuān)U明了為什么讓 floor() 返回浮點(diǎn)數(shù)可能有用(對(duì)于像 float('inf') 和 <代碼>浮動(dòng)('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() 返回整數(shù)(并且對(duì)于前面提到的特殊情況返回溢出錯(cuò)誤).

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

那么 int()floor() 現(xiàn)在有什么區(qū)別?

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

推薦答案

floor() 循環(huán) down.int() 截?cái)?/em>.使用負(fù)數(shù)時(shí)區(qū)別很明顯:

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

對(duì)負(fù)數(shù)進(jìn)行四舍五入意味著它們遠(yuǎn)離 0,截?cái)嗍顾鼈兏咏?0.

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

換句話說(shuō),floor() 總是會(huì)低于或等于原始值.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.

這篇關(guān)于Python 3 中的 int() 和 floor() 有什么區(qū)別?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點(diǎn)小數(shù)點(diǎn)/精度)
Converting Float to Dollars and Cents(將浮點(diǎn)數(shù)轉(zhuǎn)換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計(jì)算可以返回 NaN?)
Python float to ratio(Python浮動(dòng)比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數(shù)字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 美日韩精品 | 亚洲午夜精品视频 | 国产成人精品久久二区二区 | 成人在线一区二区 | 国产黄色在线观看 | 91精品国产91久久久久游泳池 | 色综合久久久久 | 成人在线一区二区 | 2一3sex性hd | 国产乱码精品一品二品 | 亚洲一区二区三区四区五区中文 | 国产在线精品一区二区 | 国产91中文| 欧美日韩成人在线 | 91亚洲国产| 国产高清久久 | 欧美日韩国产精品一区 | 精品一区二区免费视频 | 亚洲综合无码一区二区 | 成人免费网站www网站高清 | av国产精品 | 欧美videosex性极品hd | 欧美视频二区 | 欧美一区二 | 精品国产一区二区在线 | 亚洲播放一区 | 天天操天天射综合网 | 精品一二区| 日韩毛片| 不卡一二三区 | 欧美精品久久 | 日本黄色大片免费 | 殴美成人在线视频 | 超碰在线免费 | 亚洲免费网址 | 国产精品美女久久久久久久网站 | 中文字幕高清av | 成人免费在线视频 | 一区二区小视频 | 久久99精品久久久久久国产越南 | 亚洲国产aⅴ成人精品无吗 欧美激情欧美激情在线五月 |