`/` Operator's True Division Revolution
Python 3's default "true division" (e.g., `1/2` equals `0.5`), backported via `from __future__ import division`, fundamentally changed the `/` operator's behavior. In Python 2, integer division (`1/2` resulting in `0`) was the default, often leading to unexpected results, which true division corrected by always returning a float.
The top 3
- Python 2 `/` Division: Silent Data Truncation: Before Python 3, the `/` operator between two integers performed floor division, silently truncating decimal parts and often leading to unexpected errors and mathematical inaccuracies.
- Python 3's `/` Operator: Universal Float Division: Python 3 revolutionized division by making the `/` operator consistently perform true division, always returning a float result, regardless of whether the operands are integers or floats.
- `//` Operator: Python 3's Explicit Integer Division: To provide a clear mechanism for integer division, Python 3 introduced the `//` operator, which explicitly performs floor division, returning the largest integer less than or equal to the true division result.
Sources
Open the full topic