Python 基礎(chǔ)教程
modf() 方法返回x的整數(shù)部分與小數(shù)部分,兩部分的數(shù)值符號與x相同,整數(shù)部分以浮點(diǎn)型表示。
以下是 modf() 方法的語法:
import math math.modf( x )
注意:modf()是不能直接訪問的,需要導(dǎo)入 math 模塊,通過靜態(tài)對象調(diào)用該方法。
以下展示了使用 modf() 方法的實(shí)例:
#!/usr/bin/python import math # This will import math module print "math.modf(100.12) : ", math.modf(100.12) print "math.modf(100.72) : ", math.modf(100.72) print "math.modf(119L) : ", math.modf(119L) print "math.modf(math.pi) : ", math.modf(math.pi)
以上實(shí)例運(yùn)行后輸出結(jié)果為:
math.modf(100.12) : (0.12000000000000455, 100.0) math.modf(100.72) : (0.71999999999999886, 100.0) math.modf(119L) : (0.0, 119.0) math.modf(math.pi) : (0.14159265358979312, 3.0)其他擴(kuò)展