What’s New in Python 3.6 ? | New Features in Python 3.6

1. Python 3.6 Tutorial

In this article on Python 3.6, we will discuss the following new features in Python 3.6. Moreover, we will discuss

New Syntax Features of Python 3.6

New Modules in Python 3.6

Improved Python 3.6 Modules

So, let’s start the Python 3.6 Tutorial.

What’s New in Python 3.6? | New Features in Python 3.6

2. What’s new in Python 3.6?

We know that the future belongs to Python 3.x. But we have a number of versions in Python 3000. For example, Python 3.3.3 and Python 3.4.3. The latest version of Python is 3.6. So, let’s see what’s new in Python 3.6 and how it is different from older versions, Python 3.6 performance and features.

3. New Syntax Features of Python 3.6

With Python 3.6, we see some new syntax features. Let’s take a look.

a. PEP 498 (Formatted String Literals)

You guessed it right. PEP 498 introduces f-strings.

An f-string is a string that you can format to put values inside it. For this, we precede the string with an ‘f’ or an ‘F’. We mention the variables inside curly braces.

>>> hometown,city='Ahmedabad','Indore'
>>> print(f"I love {hometown}, but I live in {city}")

With PEP 520, the natural ordering of attributes in a class is preserved in the class’ __dict__ attribute. Now, the default effective class ‘execution’ namespace is an insertion-order-preserving mapping.

k. PEP 468 (Preserving Keyword Argument Order)

Python now guarantees that **kwargs in a function signature is an insertion-order-preserving mapping.

l. PEP 523 (Adding a frame evaluation API to CPython)

PEP 523 introduces an API to make frame evaluation pluggable at the C level. This way, tools like debuggers and JITs can intercept frame evaluation before the Python code even begins to execute.

4. Other Additions in Python 3.6

The PYTHONMALLOC environment variable allows us to set the Python memory allocators and install debug hooks.

New dict implementation- Now, dict() uses between 20% and 25% less memory compared to Python 3.5.

Earlier, it would give you a SyntaxWarning if you did not use a ‘global’ or ‘nonlocal’ statement before the first use of the affected name in that scope.

Now, Import raises the new exception ModuleNotFoundError, which is a subclass of ImportError. Code that checks for ImportError still works.

The interpreter now abbreviates long sequences of repeated traceback lines as “[Previous line repeated {count} more times]”.

Class methods that rely on zero-argument super() now work perfectly when we call them from metaclass methods at class creation.

Now, we can set a special method to None when we want to indicate that the operation is unavailable. For instance, a class that sets __iter__() to None isn’t iterable.

The is some this what’s extremely new in Python 3.6.

5. New Modules in Python 3.6

a. secrets

Python 3.6 introduces a new module, ‘secrets’. This module lends us a way to reliably generate cryptographically strong pseudo-random values. Using these, we can manage secrets like account authentication, tokens, and so.

What’s new in python 3.6 – Secrets

Any doubt yet in What’s new in Python 3.6 tutorial because now there is a long list of Improved modules. Also refer this article on Python Modules vs Packages.

6. Improved Python 3.6 Modules

Why stop at what we have, when we can tweak it into something even more awesome? Python 3.6 makes the following improvements:

array – Now, exhausted iterators of array.array stay exhausted even when the iterated array extends. This is in consistence with other mutable sequences’ behavior.

asyncio – With Python 3.6, the asyncio module is no longer provisional; its API is now stable.

binascii – Now, the function b2a_base64() accepts an optional newline keyword. This way, it can control whether the newline character appends to the return value.

cmath – Python 3.6 added a new constant cmath.tau(τ).

>>> from cmath import tau
>>> tau

6.283185307179586

collections – Here’s all that is new in the ‘collections’ module:

Collection ABC- to represent sized iterable container classes.

Reversible ABC- to represent iterable classes. These also provide the method __reversed__().

AsyncGenerator ABC- to represent asynchronous generators.

Other than these, the namedtuple() function will now accept an optional keyword argument ‘module’. Now, the arguments ‘verbose’ and ‘rename’ for namedtuple() are keyword-only. Finally, we can now pickle recursive collections.deque instances.

concurrent.futures – Now, the class constructor ThreadPoolExecutor accepts an optional thread_name_prefix argument. This lets us customize thread names for the thread created by the pool.

contextlib – The new contextlib.AbstractContextManager class provides an ABC for context managers. This provides a sensible default implementation for __enter__().

datetime – Python 3.6 has a fold attribute for the datetime and time classes. This disambiguates local time.

typing – This module now has an improved support for generic type aliases. Also, new classes include typing.ContextManager and typing.Collection.

unicodedata – This module now uses data from Unicode 9.0.0.

unittest.mock – New methods include Mock.assert_called() and Mock.assert_called_once().

urllib.request – If an HTTP request has a file or iterable body, other than a bytes object, but no Content-Length header, it does not throw an error. Now, AbstractHTTPHandler uses chunked transfer encoding.

urllib.robotparser – The RobotFileParser now supports the Crawl-delay and Request-rate extensions.

venv – venv now accepts a new parameter- –prompt. This is an alternative prefix for the virtual environment.

warnings – The warnings.warn_explicit() function now has an optional ‘source’ parameter.

winreg – What’s new? The 64-bit integer type REG_QWORD.

winsound – winsound now allows us to pass keyword arguments to Beep, MessageBeep, and PlaySound.

bg. xmlrpc.client – This module now supports unmarshalling additional data types that are used by the Apache XML-RPC implementation for numerics and None.

zipfile – The class method ZipInfo.from_file() allows us to make a ZipInfo instance from a filesystem file.

zlib – We can now pass keyword arguments to functions compress() and decompress().

So, this is all on what’s new in Python 3.6 Tutorial. Hope you like our explanation.

7. Conclusion

In this article on what’s new in Python 3.6, we discussed what changes have been made to Python 3.5 to make it Python 3.6. Tell us how you like them the what’s new in Python 3.6 article.

No Responses

Hi,
I am new to Python and Data Science and looking for some blogs or websites where I can find some problem statements or Programs for Hands on purpose in Python and Machine Learning.
Could you please suggest if possible.