How to divide in Python

In this tutorial you will learn how to divide number in python. For division of number python has it’s own operator. Mostly we used “/” operator to divide in python because it return value with decimals.

There are two types of operator in python

  • /:  This division operator in python, divide the number and return floating point value and this type of division is also called floating point division.
quotient = 5 / 2
print(quotient)

#output: 2.5
  • //: This division operator in python, divide the number and returns a whole number and this type of division is also called as integer type division.
quotient = 5 // 2
print(quotient)

#output: 2

Examples: Types of Division in python

# Dividing an integer by an integer
print("The answer for 5/2: ")
print(5/2)
print("The answer for 5//2: ")
print(5//2)
print("\n")

# Dividing an integer by a float
print("The answer for 5/2.75: ")
print(5/2.75)
print("The answer for 5//2.75: ")
print(5//2.75)
print("\n")

#Dividing a float by an integer
print("The answer for 5.5/2: ")
print(5.5/2)
print("The answer for 5.5//2: ")
print(5.5//2)
print("\n")

#Dividing a float by an float
print("The answer for 5.5/2.5: ")
print(5.5/2.5)
print("The answer for 5.5//2.5: ")
print(5.5//2.5)
Was this article helpful?
YesNo

1 thought on “How to divide in Python”

Leave a Comment