Introduction
Welcome Ninjas! This blog will follow a series of topics like ceil() in python and floor() in python, but before that, we will discuss the basics of Python language to make you familiar with it.
Before discussing, ceil() in python and floor() in python, let's see what Python is. Guido van Rossum developed Python during 1985- 1990. Python is a high level open source programming language that is gaining popularity nowadays. Python is a general-purpose language. It is an interpreted but not compiled language. Other features of Python include- being interactive and object-oriented. Python is a dynamically-typed language. Now let's look into the primary concern of our blog i.e. ceil() in python and floor() in python.
Let us get started!
Check this out, ping command in linux
What are Ceil() and Floor() in Python?
Ceil() in Python
ceil(n) in python is an inbuilt math function in Python that returns the smallest integer number which is greater than or equal to n.
For example, let's say n=3.6, then the smallest integer greater than it is 4; therefore the ceil of 3.6 would be 4.
Syntax
import math
math.ceil(number)
In the above syntax:
- math is the standard Python module that contains mathematical operations. You have to import this module before using the ceil() function.
- ceil() is the function present in the math module for performing the ceiling operation.
- number is the value for which you want to find the smallest integer that is greater than or equal to this number.
Implementation
#Import the math library first
import math
#using function .ceil() of math lib
print(math.ceil(3.6))
print(math.ceil(-3.6))
Floor() in Python
floor(n) in python is an inbuilt mathematical function in Python that returns the largest integer not greater than n.
For example, for any positive real number, say 3.6, the largest integer which is not greater than 3.6 is 3.
Syntax
import math
math.floor(number)
In the above syntax:
- math is the standard Python module that contains mathematical operations. You have to import this module before using the floor() function.
- floor() is the function present in the math module for performing the floor operation.
- number is the value for which you want to find the largest integer that is less than or equal to this number.
Implementation
#Import the math library first
import math
#using function .floor() of math lib
print(math.floor(3.6))
print(math.floor(-3.6))
Also see, Python Filter Function