Python Math ceil() Method
The Python Math ceil(x) function returns the smallest integer greater than or equal to x.
Python Math ceil() Syntax
The following is the syntax of the ceil() method:
import math
math.ceil( x )
Note: ceil() is not directly accessible, you need to import the math module and call the method through a static object.
Python Math ceil() Parameters
x – The numeric expression.
Python Math ceil() Return Value
The function returns the smallest integer that is greater than or equal to x.
Python Math ceil() Example#1
The following shows an example of using the ceil() method:
#!/usr/bin/python3
import math
x = 33.7
# returning the ceil of 33.7
print ("The ceil of 33.7 is : ", end ="")
print (math.ceil(x))
Output:
Python Math ceil() Example#2
#!/usr/bin/python3
import math
# prints the ceil using ceil() method
print ("math.ceil(-13.1) : ", math.ceil(-13.1))
print ("math.ceil(101.96) : ", math.ceil(101.96))
Output:
Python Math ceil() Example#3
#!/usr/bin/python3
import math # import math module
print ("math.ceil(math.pi) : ", math.ceil(math.pi))
Output: