如何在 Python 中判斷浮點數是否是整數?


要判斷一個浮點數是否是整數,請使用 float.is_integer() 方法。例如:

print((10.0).is_integer())
print((15.23).is_integer())

它將輸出以下內容

True
False

更新於:2020 年 6 月 17 日

1000+次瀏覽量

開啟您的職業之旅

透過完成課程獲得認證

開始使用
廣告
© . All rights reserved.