# Division Operators in Python

## Division Operators in Python

Consider the below statements in Python.

 `# A Python program to demonstrate the use of` `# "//" for integers` `print` `(``5``/``/``2``)` `print` `(``-``5``/``/``2``)`

Output:

```2
-3```

The first output is fine, but the second one may be surprised if we are coming Java/C++ world. In Python, the “//” operator works as a floor division for integer and float arguments. However, the operator / returns a float value if one of the arguments is a float (this is similar to C++)

Note:

The “//” operator is used to return the closest integer value which is less than or equal to a specified expression or value. So from the above code, 5//2 returns 2. You know that 5/2 is 2.5, the closest integer which is less than or equal is 2[5//2].( it is inverse to the normal maths, in normal maths the value is 3).

 `# A Python program to demonstrate use of` `# "/" for floating point numbers` `print` `(``5.0``/``2``)` `print` `(``-``5.0``/``2``)`

Output:

```2.5
-2.5```

The real floor division operator is “//”. It returns floor value for both integer and floating point arguments.

 `# A Python program to demonstrate use of` `# "//" for both integers and floating points` `print` `(``5``/``/``2``)` `print` `(``-``5``/``/``2``)` `print` `(``5.0``/``/``2``)` `print` `(``-``5.0``/``/``2``)`

Output:

```2
-3
2.0
-3.0```

Last Updated on October 15, 2021 by admin

## Python | Pandas Index.value_counts()Python | Pandas Index.value_counts()

Pandas Index.value_counts() function returns object containing counts of unique values. The resulting object will be

## Python program to convert seconds into hours, minutes and secondsPython program to convert seconds into hours, minutes and seconds

Python program to convert seconds into hours, minutes and seconds Given an integer n (in seconds), convert

## Python ModulesPython Modules

Python Modules A Python module is a file containing Python definitions and statements. A module

## Global and Local Variables in PythonGlobal and Local Variables in Python

Global and Local Variables in Python Global variables are those which are not defined inside any

## Pandas DataFrame.set_index()Pandas DataFrame.set_index()

Python – Pandas DataFrame.set_index()   Pandas set_index() is a method to set a List, Series

## Python – Merging two DictionariesPython – Merging two Dictionaries

Merging two Dictionaries in Python There are various ways in which Dictionaries can be merged

## Python – Call function from another filePython – Call function from another file

Python – Call function from another file Given a Python file, we need to call