Skip to content
Related Articles

Related Articles

Division Operators in Python

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 28 Jul, 2022

Division Operators allow you to divide two numbers and return a quotient, i.e., the first number or number at the left is divided by the second number or number at the right and returns the quotient. 

There are two types of division operators: 

(i) Float division: 

The quotient returns by this operator is always a float number, no matter if two numbers are integer. For example:


(ii) Integer division( Floor division): 

The quotient returned by this operator is dependent on the argument being passed. If any of the numbers is float, it returns output in float. It is also known as Floor division because, if any number is negative, then the output will be floored. For example:


Consider the below statements in Python.


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



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 division operator ‘/’ returns always a float value.

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, and 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)



The real floor division operator is “//”. It returns the 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)



See this for example. 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!