Python modf()返回两项元组中x的小数和整数部分。这两个部分都有与x相同的符号。
import math math.modf( x )
x - 这是一个数值表达式。
此方法在两项元组中返回x的小数部分和整数部分。这两个部分都有与x相同的符号。整数部分作为浮点数返回。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/number-modf.html
来源:LearnFk无涯教程网
以下示例显示modf()方法的用法。
#!/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)
当无涯教程运行上面的程序时,它产生以下输出-
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)
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)