Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Daniel Arbuckle???s Mastering Python

You're reading from   Daniel Arbuckle???s Mastering Python Build powerful Python applications

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781787283695
Length 274 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Daniel Arbuckle Daniel Arbuckle
Author Profile Icon Daniel Arbuckle
Daniel Arbuckle
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Python Primer FREE CHAPTER 2. Setting Up 3. Making a Package 4. Basic Best Practices 5. Making a Command-Line Utility 6. Parallel Processing 7. Coroutines and Asynchronous I/O 8. Metaprogramming 9. Unit Testing 10. Reactive Programming 11. Microservices 12. Extension Modules and Compiled Code

What's new in modern Python

In this section, we're going to take a look at a few of the changes that have occurred in the latest releases of Python, specifically we will look at these:

  • The syntactic changes
  • The changes in the packages
  • Other changes

Let's get started!

The changes in the syntactic

Since version 3.5, Python has three new groups of syntactic editions. The first of these groups is the introduction of keywords for describing coroutines. Python already supported coroutines, but the keywords make things clear and sometimes simpler. We'll be discussing coroutines in depth in a later chapter, so we won't go into this any further now.

The second piece of the new syntax is the introduction of the @ symbol as an infix binary operator. This means that placing an @ symbol between two sub-expressions is now a valid Python expression, just like placing a + symbol between the sub-expressions would be as shown in the following screenshot:

However, since no built-in data type supports the @ symbol operator yet, we won't be finding much use for it in this book. The intended semantic meaning of the @ symbol is that it should represent matrix multiplication and it was added to improve support for an interoperability between third-party packages that implement matrixes and matrix operations.

The third piece of new syntax is an expansion of Python's pre-existing syntax for using lists and dictionaries to provide the parameter values when invoking a function.

Before, it was possible to put an asterisk (*) before a list of values to indicate that those values should be assigned to the parameters in the same order that they appeared in the list. Here is the code example for a single asterisk:

Similarly, * before two values was used to indicate that the values in a dictionary with text string keys should be assigned to the function's parameters by name, as shown here:

The new syntax is just that we can now use more than one list or dictionary in this way, and that we can use the same asterisk and double asterisk syntax for constructing tuples, lists, dictionaries, and sets.

We mentioned earlier that while Python attaches data types to data values rather than variables, it is possible to use function annotations to describe the expected types of function parameters' return values.

Changes in packages

Python now includes a package called typing in the standard library that contains classes and functions supporting the usage of type hints.

Python also includes a package called zipapp in the standard library.

For typing visit the following website:
https://docs.python.org/3/library/typing.html

For zipapp, visit this website:
https://docs.python.org/3/library/zipapp.html

The zipapp package makes it easy to construct .pyz files. A .pyz file is an archive file containing Python code and arbitrary read-only data, which the Python runtime is able to execute as a self-contained program. Once a program is debugged and ready for distribution, packaging it into a .pyz file is a simple and smart way to hand it to the users.

Other changes in Python packages

Some low-level improvements have been made in Python since version 3.5, such as faster reading of filesystem directories, automatic retrying of interrupted operating system calls, and a math.isclose function for checking whether two numbers are approximately equal.

There are also a bunch of more minor additions that improve things throughout the standard library, all backwards compatible with earlier Python 3 versions.

In the rare cases where something is added that breaks backwards compatibility, it's not enabled by default. For such a change, if we want to use it, we'd have to specifically mark our code as supporting the change. Those changes will not become standard until two versions later, so a breaking change in Python 3.5 would not become the default until Python version 3.7, with Python 3.5 and 3.6 issuing warnings when they encounter code that depends on the changing feature.

In Python 3.5, there was only one such change-a small and smart alteration in the iteration protocol. It shouldn't have any effect on code that works properly, but technically it's a change in the interface and so it gets the full wait two versions treatment.

If you want more detail about any of these changes I've mentioned, or if you ever want to find out what's changed between versions of Python, the documentation on https://docs.python.org/3/ always contains a what's new document that goes into some detail about new features and provides links to the full documentation.

For details on the Python 3.6 what's new document, visit the following link:
https://docs.python.org/3/whatsnew/3.6.html

I always look forward to reading the what's new document for each release of Python, to find out what new toys I've just been handed.

So, we've now taken a high-level view of the Python standard library, introducing us to some of the more useful items it contains. That brings us to the end of our Python primer.

You have been reading a chapter from
Daniel Arbuckle???s Mastering Python
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781787283695
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime