概述:返回x的整数部分与小数部分,两部分的数值符号与x相同,整数部分以浮点型表示。
该函数使用前需要引入math函数
语法:
math.modf(x)
1. 直接输出
import math
print(math.modf(2))
运行结果为:
(0.0, 2.0)
2.赋值给变量
import math
a=math.modf(6.78)
print(a,type(a))
运行结果为:
(0.7800000000000002, 6.0) <class 'tuple'>
为元组类型
3.赋值给两个变量
import math
a,b=math.modf(3.45)
print(a,type(a))
print(b,type(b))
运行结果为:
0.4500000000000002 <class 'float'>
3.0 <class 'float'>