Top 3 Python 3 Features Backported by Future
`python-future`'s `future.builtins` package provides backports and remappings for 20 built-in functions and types with different semantics. Key backported features enabling Python 3 style in Python 2 include the `print()` function, true division (`/`), and `unicode_literals` (via `__future__` imports), which significantly eased migration efforts.
The top 3
- Python 3 `print` Function: Flexibility Gains: The `print` function in Python 3, backported by `python-future` (via `from __future__ import print_function`), replaced the less flexible `print` statement. This change introduced keyword arguments like `sep` and `end`, allowing for easier customization of output formatting and redirection to files.
- `/` 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.
- `unicode_literals`: Python 2's String Simplifier: The `unicode_literals` feature, enabled by `from __future__ import unicode_literals` and backported by `python-future`, made all string literals Unicode by default in Python 2. This addressed Python 2's `str` (bytes) vs. `unicode` (text) confusion, simplifying string handling and reducing `UnicodeError` issues prevalent in mixed-type operations.
Sources
Open the full topic