无涯教程-Python - ceil(x)函数

51 阅读1分钟

Python number methodceil()返回x的上限值-不小于x的最小整数。

ceil(x) - 语法

import math

math.ceil( x )

  • x  -  这是一个数值表达式。

ceil(x) - 返回值

此方法返回不小于x的最小整数。

ceil(x) - 示例

以下示例显示了ceil()方法的用法。

#!/usr/bin/python
import math   # This will import math module

print "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

参考链接

www.learnfk.com/python/numb…