Python number methodceil()返回x的上限值-不小于x的最小整数。
ceil(x) - 语法
import mathmath.ceil( x )
x - 这是一个数值表达式。
ceil(x) - 返回值
此方法返回不小于x的最小整数。
ceil(x) - 示例
以下示例显示了ceil()方法的用法。
#!/usr/bin/python import math # This will import math moduleprint "math.ceil(-45.17) : ", math.ceil(-45.17) print "math.ceil(100.12) : ", math.ceil(100.12) print "math.ceil(100.72) : ", math.ceil(100.72) print "math.ceil(119L) : ", math.ceil(119L) print "math.ceil(math.pi) : ", math.ceil(math.pi)
当无涯教程运行上面的程序时,它产生以下输出-
math.ceil(-45.17) : -45.0 math.ceil(100.12) : 101.0 math.ceil(100.72) : 101.0 math.ceil(119L) : 119.0 math.ceil(math.pi) : 4.0