Latest web development tutorials

Python3 ceil () function

Python3 digital Python3 digital


description

ceil (x) function returns a value greater than or equal to the smallest integer x.


grammar

The following is the syntax ceil () method:

import math

math.ceil( x )

Note: ceil () is not directly accessible, you need to import math module, invoke the method through static object.


parameter

x - numeric expression.

return value

Return a function of x is greater than or equal to the smallest integer.

Examples

The following shows an example of using ceil () method:

#!/usr/bin/python3
import math   # 导入 math 模块

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(math.pi) : ", math.ceil(math.pi))

After running the above example output is:

math.ceil(-45.17) :  -45
math.ceil(100.12) :  101
math.ceil(100.72) :  101
math.ceil(math.pi) :  4

Python3 digital Python3 digital