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:
pythona, b = 7, 3 result = a // b print(result)- Output:
2
- Output:
Float Division:
- Float division means the result includes the decimal part.
- Use the
/operator for float division. Example:
pythona, b = 7, 3 result = a / b print(result)- Output:
2.3333333333333335
- Output:
Examples and Exercises:
Integer Division with Float Values:
pythona, b = 7.2, 3.1 result = a // b print(result)- Output:
2.0
- Output:
Basic Float Division:
pythona, b = 7, 3 result = a / b print(result)- Output:
2.3333333333333335
- Output:
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!