This article mainly introduces the floor () method in Python, which is the basic knowledge for getting started with Python. If you need it, refer to floor () returns the maximum integer (rounded down) not greater than x ).
Syntax
The following is the syntax of the floor () method:
import mathmath.floor( x )
Note: This function cannot be directly accessed. Therefore, we need to import the math module and then use the static object of math to call this function.
Parameters
- X -- this is a numeric expression.
Return Value
This method returns the maximum integer not greater than x.
Example
The following example shows how to use the floor () method.
#!/usr/bin/pythonimport math # This will import math moduleprint "math.floor(-45.17) : ", math.floor(-45.17)print "math.floor(100.12) : ", math.floor(100.12)print "math.floor(100.72) : ", math.floor(100.72)print "math.floor(119L) : ", math.floor(119L)print "math.floor(math.pi) : ", math.floor(math.pi)
When we run the above program, it will produce the following results:
math.floor(-45.17) : -46.0math.floor(100.12) : 100.0math.floor(100.72) : 100.0math.floor(119L) : 119.0math.floor(math.pi) : 3.0