Python modf() 函數


描述

modf() 方法返回x的整數部分與小數部分,兩部分的數值符號與x相同,整數部分以浮點型表示。


語法

以下是 modf() 方法的語法:

import math

math.modf( x )

注意:modf()是不能直接訪問的,需要導入 math 模塊,通過靜態對象調用該方法。


參數

  • x -- 數值表達式。

返回值

返回x的整數部分與小數部分,


實例

以下展示了使用 modf() 方法的實例:

#!/usr/bin/python3
import math   # 導入 math 模塊

print ("math.modf(100.12) : ", math.modf(100.12))
print ("math.modf(100.72) : ", math.modf(100.72))
print ("math.modf(119) : ", math.modf(119))
print ("math.modf(math.pi) : ", math.modf(math.pi))

以上實例運行后輸出結果為:

math.modf(100.12) :  (0.12000000000000455, 100.0)
math.modf(100.72) :  (0.7199999999999989, 100.0)
math.modf(119) :  (0.0, 119.0)
math.modf(math.pi) :  (0.14159265358979312, 3.0)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM