python math.ceil()方法

math.ceil()方法

python math模块ceil()方法,可以取到一个大于等于参数的最小整数值。


ceil()语法

ceil(x, /)

python源码中对ceil()方法的介绍:

    Return the ceiling of x as an Integral.
    
    This is the smallest integer >= x.

参数

参数描述
xreal number数值类型的参数,比如int整型,float浮点型

提示:如果传递的不是数值number类型的参数,python将抛出TypeError。


ceil()返回值

smallest integer,即python的int整数类型值。


ceil()实例代码

>>> import math
>>> math.ceil(1.0)
1
>>> math.ceil(1.01)
2
>>> math.ceil(1.00001)
2
>>> math.ceil([1]) #参数list
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not list
>>> math.ceil('1') #参数为str
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be real number, not str

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.