The ceil() Python number method is supposed to return the ceiling value of x, where x is the smallest integer but not less than x. The ceil() method in Python is, therefore, one of the Python Math functions which is used for returning the lowest integer value which is, further greater than or equal to the specific expression or number. In case the number already stands to be an integer then, in that case, a similar number is returned.
Following is the syntax for ceil() method:
import math math.ceil( x )
Note - This function is not accessible directly, so we need to import the math module, and then we need to call this function using a math static object.
x - This is a numeric expression.
This method returns the smallest integer not less than x.
The following example shows the usage of ceil() method.
#!/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)
When we run the above program, it produces the following result:
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
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.