BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Python 3.5 Brings New Language Features and Library Modules

Python 3.5 Brings New Language Features and Library Modules

This item in japanese

Recently released Python 3.5 brings a host of changes, including several new syntax features, new library modules, improvements to the standard library, and to security.

Syntax features

Python 3.5 introduces three new syntactic features:

  • coroutines with async-await syntax, which allows developers to write code as if it were sequential. In fact, the compiler will implement it through a sequence of coroutines, thus making it effectively concurrent. In the following example, multiple await statements can be thought of as executing sequentially, but they would not cause any actual block:

    async def read_data(db):
    data = await db.fetch('SELECT ...')
    if (data...)
        await api.send(data ...')
    
  • a matrix multiplication operator that allows to express the multiplication between matrices as a @ b. This will allow to write:

    S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
    
    instead of:
    S = dot((dot(H, beta) - r).T, dot(inv(dot(dot(H, V), H.T)), dot(H, beta) - r))
    	
  • unpacking generalization, which is meant to extend the allowed usage of the * unpacking operator and make it possible to use it multiple times in function calls, or inside of tuples:

    >>> print(*[1], *[2], 3)
    1 2 3
    >>> dict(**{'x': 1}, y=2, **{'z': 3})
    {'x': 1, 'y': 2, 'z': 3}
    
    
    >>> *range(4), 4
    (0, 1, 2, 3, 4)
    

Library Modules

New library modules in Python 3.5 introduce:

  • type hints, which aim to enable type checking annotations to 3rd party modules while also allowing unaltered execution if desired.
  • new zipapp module provides an API and command line tool for creating executable Python Zip Applications.

Other changes brought by Python 3.5 include:

Additionally, SSLv3 has been disabled by default, although it can be enabled if required.

Rate this Article

Adoption
Style

BT