import math math.modf( x )
註:此函式無法直接存取,所以我們需要匯入 math 模組,然後用數學靜態物件呼叫這個函式。
x -- 這是一個數位表示式
此方法返回x的整數和小數部分並分別放在元組中的兩專案。 兩個部分與x的符號相同。整數部分返回為float。
#!/usr/bin/python3 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(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)