Division

 

What Is Division in Python?

  • Division is an arithmetic operation where you split a number into equal parts.
  • In Python, there are two types of division: Integer Division and Float Division.

Integer Division:

  • Integer division means the result is an integer. The decimal part is ignored.
  • Use the // operator for integer division.
  • Example:

    python
    a, b = 7, 3
    result = a // b
    print(result)
    • Output: 2

Float Division:

  • Float division means the result includes the decimal part.
  • Use the / operator for float division.
  • Example:

    python
    a, b = 7, 3
    result = a / b
    print(result)  
    •  Output: 2.3333333333333335

Examples and Exercises:

  1. Integer Division with Float Values:

    python
    a, b = 7.2, 3.1
    result = a // b
    print(result)  
    • Output: 2.0
  2. Basic Float Division:

    python
    a, b = 7, 3
    result = a / b
    print(result)  
    • Output: 2.3333333333333335

Summary:

  • Division in Python can be done using integer or float division. Use // for integer results and / for float results. Practice with the examples to see how it works!