Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Modulo operator (%) in Python
Next article icon

Division Operators in Python

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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: 

  • Float division
  • Integer division( Floor division)

When an integer is divided, the result is rounded to the nearest integer and is denoted by the symbol “//”. The floating-point number “/” stands for floating division, which returns the quotient as a floating-point number.

Types of Division in Python

Float division

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

Python
print(5/5) print(10/2) print(-10/2) print(20.0/2) 

Output
1.0 5.0 -5.0 10.0 

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:

Python
print(5//5) print(3//2) print(10//3) 

Output
1 1 3 

Consider the below Python program to demonstrate the use of “//” for integers.

Python
print (5//2) print (-5//2) 

Output
2 -3 

Explanation: The first output is fine, but the second one may be surprising if we are coming to the 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).

Example: A Python program to demonstrate use of “/” for floating point numbers.

Python
print (5.0/2) print (-5.0/2) 

Output
2.5 -2.5 

Advantages of the Division Operator

The division operator (/) is a fundamental arithmetic operator in programming languages that performs the division operation on numerical values. Here are some advantages of using the division operator:

  1. Basic arithmetic operations: The division operator is one of the basic arithmetic operations that is used in mathematics, engineering and other fields. It allows you to divide one number by another to perform calculations, such as computing the average of a set of numbers or scaling a value.
  2. Expressive syntax: The division operator provides a concise and expressive syntax for performing division operations in code. Instead of writing a complex expression with multiple arithmetic operations, you can use the division operator to perform division in a single line of code.
  3. Precision control: The division operator allows you to control the precision of your calculations by using different data types or rounding strategies. For example, you can use floating-point division (/) to compute a decimal quotient or integer division (//) to compute a truncated quotient.
  4. Algorithmic efficiency: The division operator can be used to implement efficient algorithms for numerical computations, such as matrix multiplication, linear algebra and numerical integration. By using the division operator in these algorithms, you can reduce the number of arithmetic operations and improve the performance of your code.
  5. Mathematical modeling: The division operator is used in mathematical modeling and simulation to represent relationships between variables, such as rates of change, growth rates or probabilities. By using the division operator in these models, you can simulate and analyze complex systems and phenomena.

Overall, the division operator is a powerful and versatile operator that provides a wide range of advantages in programming and mathematics.

Is a division operator on Boolean values possible?

In Python, the division operator (/) is not defined for boolean values. If you attempt to divide two boolean values, you will get a TypeError. However, if you want to overload the division operator for a custom class that has Boolean values, you can define the __truediv__ special method. Here’s an example:

In this example, we define a MyClass that has a single attribute value, which is a boolean. We then overload the / operator by defining the __truediv__ method to perform a logical operation on the value attribute of two MyClass instances.

When we call a / b, the __truediv__ method is called with an as the first argument and b as the second argument. The method returns a new instance of MyClass with a value attribute that is the logical and of a.value and b.value.

Note that overloading the division operator for boolean values is not meaningful or useful, since division is not defined for boolean values in mathematics or in Python. The example above is just a demonstration of how to overload an operator in a custom class.

Python
class MyClass:     def __init__(self, value):         self.value = value      def __truediv__(self, other):         return MyClass(self.value and other.value)  a = MyClass(True) b = MyClass(False) c = a / b   print(c.value) 

Output
False 


Next Article
Modulo operator (%) in Python
author
kartik
Improve
Article Tags :
  • Python
  • School Programming
  • python
Practice Tags :
  • python
  • python

Similar Reads

  • Python Operators
    In Python programming, Operators in general are used to perform operations on values and variables. These are standard symbols used for logical and arithmetic operations. In this article, we will look into different types of Python operators. OPERATORS: These are the special symbols. Eg- + , * , /,
    6 min read
  • Precedence and Associativity of Operators in Python
    In Python, operators have different levels of precedence, which determine the order in which they are evaluated. When multiple operators are present in an expression, the ones with higher precedence are evaluated first. In the case of operators with the same precedence, their associativity comes int
    4 min read
  • Python Arithmetic Operators

    • Python Arithmetic Operators
      Python operators are fundamental for performing mathematical calculations. Arithmetic operators are symbols used to perform mathematical operations on numerical values. Arithmetic operators include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). OperatorDescriptionS
      5 min read
    • Difference between / vs. // operator in Python
      In Python, both / and // are used for division, but they behave quite differently. Let's dive into what they do and how they differ with simple examples. / Operator (True Division)The / operator performs true division.It always returns a floating-point number (even if the result is a whole number).I
      2 min read
    • Python - Star or Asterisk operator ( * )
      The asterisk (*) operator in Python is a versatile tool used in various contexts. It is commonly used for multiplication, unpacking iterables, defining variable-length arguments in functions, and more. Uses of the asterisk ( * ) operator in PythonMultiplicationIn Multiplication, we multiply two numb
      3 min read
    • What does the Double Star operator mean in Python?
      The ** (double star)operator in Python is used for exponentiation. It raises the number on the left to the power of the number on the right. For example: 2 ** 3 returns 8 (since 2³ = 8)It is one of the Arithmetic Operator (Like +, -, *, **, /, //, %) in Python and is also known as Power Operator. Pr
      2 min read
    • Division Operators in Python
      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: Float divisionInteger division( Floor division)When an in
      5 min read
    • Modulo operator (%) in Python
      Modulo operator (%) in Python gives the remainder when one number is divided by another. Python allows both integers and floats as operands, unlike some other languages. It follows the Euclidean division rule, meaning the remainder always has the same sign as the divisor. It is used in finding even/
      4 min read
    • Python Logical Operators

      geeksforgeeks-footer-logo
      Corporate & Communications Address:
      A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
      Registered Address:
      K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
      GFG App on Play Store GFG App on App Store
      Advertise with us
      • Company
      • About Us
      • Legal
      • Privacy Policy
      • In Media
      • Contact Us
      • Advertise with us
      • GFG Corporate Solution
      • Placement Training Program
      • Languages
      • Python
      • Java
      • C++
      • PHP
      • GoLang
      • SQL
      • R Language
      • Android Tutorial
      • Tutorials Archive
      • DSA
      • Data Structures
      • Algorithms
      • DSA for Beginners
      • Basic DSA Problems
      • DSA Roadmap
      • Top 100 DSA Interview Problems
      • DSA Roadmap by Sandeep Jain
      • All Cheat Sheets
      • Data Science & ML
      • Data Science With Python
      • Data Science For Beginner
      • Machine Learning
      • ML Maths
      • Data Visualisation
      • Pandas
      • NumPy
      • NLP
      • Deep Learning
      • Web Technologies
      • HTML
      • CSS
      • JavaScript
      • TypeScript
      • ReactJS
      • NextJS
      • Bootstrap
      • Web Design
      • Python Tutorial
      • Python Programming Examples
      • Python Projects
      • Python Tkinter
      • Python Web Scraping
      • OpenCV Tutorial
      • Python Interview Question
      • Django
      • Computer Science
      • Operating Systems
      • Computer Network
      • Database Management System
      • Software Engineering
      • Digital Logic Design
      • Engineering Maths
      • Software Development
      • Software Testing
      • DevOps
      • Git
      • Linux
      • AWS
      • Docker
      • Kubernetes
      • Azure
      • GCP
      • DevOps Roadmap
      • System Design
      • High Level Design
      • Low Level Design
      • UML Diagrams
      • Interview Guide
      • Design Patterns
      • OOAD
      • System Design Bootcamp
      • Interview Questions
      • Inteview Preparation
      • Competitive Programming
      • Top DS or Algo for CP
      • Company-Wise Recruitment Process
      • Company-Wise Preparation
      • Aptitude Preparation
      • Puzzles
      • School Subjects
      • Mathematics
      • Physics
      • Chemistry
      • Biology
      • Social Science
      • English Grammar
      • Commerce
      • World GK
      • GeeksforGeeks Videos
      • DSA
      • Python
      • Java
      • C++
      • Web Development
      • Data Science
      • CS Subjects
      @GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
      We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
      Lightbox
      Improvement
      Suggest Changes
      Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
      geeksforgeeks-suggest-icon
      Create Improvement
      Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
      geeksforgeeks-improvement-icon
      Suggest Changes
      min 4 words, max Words Limit:1000

      Thank You!

      Your suggestions are valuable to us.

      What kind of Experience do you want to share?

      Interview Experiences
      Admission Experiences
      Career Journeys
      Work Experiences
      Campus Experiences
      Competitive Exam Experiences