Skip to main content
idego
Python

Unpacking What's in Python 3.5

Autor: Idego Group

Unpacking What's in Python 3.5

Python 3.5 introduces several improvements to the language, with unpacking generalizations being a notable convenience feature deserving attention alongside more complex enhancements like async/await and type hinting support.

The feature described in PEP 0448 enables flexible unpacking of iterables and dictionaries in function calls and assignments. Previously, developers could unpack positional arguments at the beginning of function calls, but placing unpacked arguments elsewhere caused syntax errors. Python 3.5 eliminates this restriction.

Multiple unpacking operations in single calls are also supported. Unpacking syntax extends to variable assignments as well, simplifying list and tuple composition.

Dictionary unpacking follows similar principles. Combining dictionaries previously required update method calls or collections.ChainMap. Now developers can use keyword unpacking directly. When keys overlap, later dictionaries override earlier ones, following intuitive precedence rules.

One constraint remains: iterables must be unpacked before keyword arguments in function calls.

These small syntactic improvements enhance Python's reputation for readability and brevity, collectively improving the overall programming experience.

Powiązane artykuły