日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python | 如何强制除法运算为浮点数? 除数一直舍入为0?

發布時間:2025/3/11 python 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python | 如何强制除法运算为浮点数? 除数一直舍入为0? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Until the python version 2, the division of two integers was always being rounded down to 0.

在python版本2之前, 兩個整數除法總是四舍五入為0

Consider the below example, being executed in python version 2.7,

考慮下面的示例,該示例在python版本2.7中執行,

result = 4/5 print(result)

Output

輸出量

0

Other than overcoming the python version 2.7 which is mostly outdated and not a recommended version, the above-mentioned issue can be resolved while we update the python version to 3.X

除了克服python版本2.7(大多數版本已過時,而不是推薦的版本)以外,在將python版本更新為3.X時,可以解決上述問題

result = 4/5 print(result)

Output

輸出量

0.8

Python Consoles:

Python控制臺:

Python 2.7.16 (default, Dec 13 2019, 18:00:32) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s on darwin Type "help", "copyright", "credits" or "license" for more information. >>> result = 4/5 >>> print(result) 0 Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> result = 4/5 >>> print(result) 0.8

翻譯自: https://www.includehelp.com/python/how-can-i-force-division-to-be-floating-point-division-keeps-rounding-down-to-0.aspx

總結

以上是生活随笔為你收集整理的Python | 如何强制除法运算为浮点数? 除数一直舍入为0?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。