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 math ceil Function in python Programming is


Number: A valid numerical expression to perform the ceiling.

  • If the number argument is a positive or negative number, the ceil function returns the ceiling value.
  • If the number argument is not a number, the math ceil function returns TypeError.

Python ceil Function Example

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

# Python CEIL Function Example

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('Ceiling value of Positive Number = %.2f' %math.ceil(10))
print('Ceiling value of Negative Number = %.2f' %math.ceil(-15))

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

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

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

print('Ceiling value of String Number = ', math.ceil('Python'))
Python CEIL Function
  1. Within the first two statements, We used the Python ceil Function directly on both the Positive integer and negative integer.
  2. Next two statements, We used the ceil Function 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 the ceil Function directly on multiple values.
  4. Last, We tried the math ceil Function on the String value, and it returns TypeError.