**Python** has many libraries in it; one of them is **math**. The math library is used to perform mathematical functions in Python. There are many mathematical functions the math library contains. One of which is the **floor() function**. The floor() function is used to round out a number. This function takes a single argument that is the number we want to round out. It will return the closest integer value of the number, which is less than or equal to the number.

Firstly, we need to import the math library in the program, and then we can use it as a **math.floor()**.

Table of Contents

## Syntax

`math.floor(number) `

## Example

```
import math
fm1 = math.floor(-3.05);
fm2 = math.floor(4.13);
fm3 = math.floor(0);
print("Math.floor(-3.05) = " , fm1);
print("Math.floor(4.13) = " , fm2);
print("Math.floor(0) = " , fm3);
```

## Output

In Python, this function will only take numbers as an argument and return a rounded integer. It will not accept any string, list, null, and other inputs like in JavaScript.

If you want to see in JavaScript click here.

In JavaScript, it was taking these types of inputs and returning the output accordingly. But in Python, it will throw an error if we pass any kind of input except a number.

In JavaScript, NaN was returned when we were not passing any parameter or passing the parameter as string, undefined, or array with more than one element. And it was returning 0 in the scenario when we passed an empty string, empty array, or null.

Let’s try to pass these inputs inside the math.floor() function and see what it will return in Python.

## Not passing parameter

```
import math
fm1 = math.floor();
print("Math.floor() = " , fm1);
```

## Output

## Passing String or Passing Empty String

```
import math
fm1 = math.floor(‘A’);
print("Math.floor(‘A’) = " , fm1);
```

## Output

The error will be the same for both.

## Passing Undefined

```
import math
fm1 = math.floor(undefined);
print("Math.floor(undefined) = " , fm1);
```

## Output

## Passing Array or Passing Empty Array

```
import math
fm1 = math.floor([1,2]);
print("Math.floor([1,2]) = " , fm1);
```

## Output

The error will be the same for both.

## Passing null

```
import math
fm1 = math.floor(null);
print("Math.floor(null) = " , fm1);
```

## Output

Here we saw that we are not getting the same Python results as we were getting in JavaScript. It is showing different errors/exceptions according to the input given.

## Conclusion:

This article discussed **Python math.floor() Function**. It is an inbuilt and static method of the math object in Python. This method is used to convert a given number into an integer. It will return inappropriate results if the user passes an invalid number in the parameter. We saw examples in which we passed different valid and invalid numbers returning different types of results. Python math library contains a lot more methods dealing with various mathematical operations on the numbers.