Python3 modf() 函數
描述
modf() 方法返回x的整數部分與小數部分,兩部分的數值符號與x相同,整數部分以浮點型表示。
語法
以下是 modf() 方法的語法:
import math
math.modf( x )
注意:modf()是不能直接訪問的,需要導入 math 模塊,通過靜態(tài)對象調用該方法。
參數
- 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)
更多建議: