Python ceil

The Python ceil function is used to return the smallest integer value, which is greater than or equal to the specified expression or a specific number. The syntax of the Python math ceil Function is

math.ceil(number);
  • If the number argument is a positive or negative number, it returns the ceiling value.
  • If it is not a number, the math method returns TypeError.

Python ceil Function Example

This Function allows you to find the smallest integer value, which is greater than or equal to the numeric values. In this Python ceil function example, we are going to find the ceiling values of different data types and display the output.

import math

Tup = (10.98, 20.26, 30.05, -40.95 , 50.45) # Tuple Declaration
Lis = [-10.98, 32.65, -39.59, -42.15 , 35.97] # List Declaration

print('Value of Positive Number = %.2f' %math.ceil(10))
print('Value of Negative Number = %.2f' %math.ceil(-15))

print('Value of Tuple Item = %.2f' %math.ceil(Tup[2]))
print('Value of List Item = %.2f' %math.ceil(Lis[2]))

print("The Value of 'PI' after the Ceil function is: ", math.ceil(math.pi))

print('Value of Multiple Number = %.2f' %math.ceil(10 + 20 - 40.65))

print('Value of String Number = ', math.ceil('Python'))
Python math CEIL Function Example
  1. Within the first two statements, We used this directly on both the Positive integer and negative integer and returns an integer.
  2. Next two statements, We used it on Tuple and List items. If you observe the above Python screenshot, the Math function is working perfectly on them.
  3. In the next statement, We tried this directly on multiple values.
  4. Last, We tried the math Function on the String value, and it returns TypeError.