Python 3.5 builds on strengths and borrows from Go

Ngoc Huynh

Python update includes async function, type hinting, and matrix manipulation, as developers seek wider adoption of 3.x branch

Developers for Python — the fifth most popular programming language according to the Tiobe index — now have several new features for performing asynchronous operations, matrix math, type hinting, and other functions.

Much of the functionality added to the newly released Python 3.5 echoes that of other popular languages, but that’s not to say Python has been heavily influenced by outside forces. Rather, most of the additions to Python 3.5 are meant to complement or enhance the work Python programmers are already doing.

Coroutines (async/await)

Coroutines, the single biggest addition to Python 3.5, provide a native way to perform asynchronous programming. A function labeled with the async keyword — which suspends its execution until another condition is met — makes it into a coroutine:

async def read_data(db):
data = await db.fetch(‘SELECT …’)

A function like this would wait for data to come in from the db.fetch function (also an async function), but wouldn’t block the execution of other functions.

Python has had the ability to run code asynchronously, but the syntax has been derided as “un-Pythonic” — not in line with the language’s espoused behaviors. The async/await function is meant to remedy that complaint, and it provides features similar to what languages like Go already have.

Type hinting

Type hinting, another long-awaited addition to Python, provides an option for annotating variables (including function arguments) to indicate the type of variable in use. For example:

def greet(name: str) -> str
return ‘Hello there, {}’.format(name)
For this function, the name variable is a string, as is the value returned by the function. In such cases, no type checking is performed at runtime; instead, it’s optionally performed by a third-party code analyzer.

The @ matrix multiplication operator

Math and science applications are a big part of Python’s use cases, but matrix multiplication, typically performed in those jobs, doesn’t have a standard operator in Python. The various math and science libraries available for Python implement matrix multiplication, but not consistently.

Version 3.5’s @ infix operator provides a common syntax for matrix math, with the promise of more concise and readable code (a common aspiration for Python). A future release of the NumPy math-and-stats package will also support @ for matrix multiplication at high speed.

All of Python’s future development is concentrated in the 3.x branch. While the 2.x branch is more broadly used, it is less versatile, and the tide has been slow in turning. Some key elements of the Python ecosystem have made the jump — for example, the vast majority of the most popular Python packages are now 3.x compatible.

Share the news now

Source : http://www.infoworld.com/