Python中的ceil()方法使用教程
2015-05-14 00:00
579 查看
ceil()方法返回x的值上限 - 不小于x的最小整数。
语法
以下是ceil()方法的语法:
注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。
参数
x -- 这是一个数值表达式。
返回值
此方法返回不小于x的最小整数。
示例
下面的例子显示了ceil()方法的使用。
当我们运行上面的程序,它会产生以下结果:
语法
以下是ceil()方法的语法:
import math math.ceil( x )
注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。
参数
x -- 这是一个数值表达式。
返回值
此方法返回不小于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
相关文章推荐
- Python中的ceil()方法使用教程
- 在Python中使用dict和set方法的教程
- 在Python中使用__slots__方法的详细教程
- Python类的定义、继承及类对象使用方法简明教程
- Python2.x版本中cmp()方法的使用教程
- Python2.x版本中cmp()方法的使用教程
- Python的randrange()方法使用教程
- Python的randrange()方法使用教程
- Python中的index()方法使用教程
- Python中的index()方法使用教程
- Python中List.index()方法的使用教程
- Python中List.count()方法的使用教程
- Python中zfill()方法的使用教程
- 在Python中使用swapCase()方法转换大小写的教程
- Python中使用strip()方法删除字符串中空格的教程
- Python中使用strip()方法删除字符串中空格的教程
- 在Python中使用swapCase()方法转换大小写的教程
- Python中zfill()方法的使用教程
- Python中List.count()方法的使用教程
- Python中List.index()方法的使用教程