According to the Python official online plan, the official version of Python3.6 is expected to be released in 2016-12-16, the Friday. Since May last year, the Python3.6 version has been developed, and intermittent releases of 4 alpha, 4 Beta, and a candidate version.
As a python enthusiast, I'm looking forward to the release of the new version, and I hope to try the new feature at the first time. This article is based on the Python official website article what ' s new in Python 3.6, a brief introduction to the next Python3.6 some of the new features.
If you want to try Python3.6 and do not want to destroy the native Python environment, it is recommended that you use Docker. If you don't use Docker, you can look down here http://www.jb51.net/article/94198.htm
New syntax Features
1. Format string (formatted string literals)
That is, to add an F or f prefix before the normal string, the effect is similar to Str.format (). Like what
Name = "Fred"
print (f "He said his name is {name}.") # ' He said his name is Fred. '
The effect is equivalent to:
print("He said his name is {name}.".format(**locals()))
In addition, this attribute also supports nested fields, such as:
width = Ten
precision = 4
value = Decimal. Decimal ("12.34567")
print (f "Result: {value:{width}.{ Precision} ") # ' Result: 12.35 '
2. Variable declaration syntax (variable annotations)
That is, from the beginning of Python3.5 typehints. In Python3.5, this is the use of:
From typing import List
def test (A:list[int], b:int)-> int: return
a[0] + b
print (Test ([3, 1], 2)
The grammar check here is only generated in the editor (such as Pycharm), and is not strictly checked in actual use.
In Python3.6, a new syntax is introduced:
From typing import List, Dict
primes:list[int] = []
captain:str # At this time there is no initial value
class starship:
STATS:DICT[STR, int] = {}
3, the number of underline writing (underscores in Numeric literals)
This allows you to use underscores in numbers to improve the readability of multiple digits.
A = 1_000_000_000_000_000 # 1000000000000000
b = 0x_ff_ff_ff_ff # 4294967295
In addition, "string formatting" also supports the "_" option to print a more readable string of numbers:
' {: _} '. Format (1000000) # ' 1_000_000 '
{: _x} '. Format (0xFFFFFFFF) # ' FFFF_FFFF '
4. Asynchronous generator (asynchronous generators)
In Python3.5, the new syntax async and await are introduced to implement the cooperative program. However, there is a limitation that you cannot use both yield and await in the same function body, and in Python3.6, this restriction is released, and the asynchronous generator is allowed in Python3.6:
Async DEF Ticker (delay, to): "" "Yield numbers the from 0 to the *to* every *delay*
.
" " For I in range (to):
yield I
await asyncio.sleep (delay)
5. Asynchronous parser (asynchronous comprehensions)
This allows the async for or await syntax to be used in lists list, set set, and dictionary dict parsers.
result = [I async for I-aiter () If I% 2] result
= [await fun () to fun in Funcs if await condition ()]
New Add Module
A new module is added to the Python standard library (the Standard Library): Secrets. The module is used to generate some more secure random numbers to manage data such as passwords, account authentication, security tokens, and related secrets. You can refer to the official documentation for your specific use: Secrets
Other new features
1. The new PYTHONMALLOC environment variable allows developers to set up memory allocator and register the debug hooks.
2, the Asyncio module is more stable and efficient, and is no longer a temporary module, the API is also stable version of the.
3, the typing module also has a certain improvement, and is no longer a temporary module.
4, Datetime.strftime and Date.strftime begin to support the ISO 8601 time identifier%g,%u,%V.
5. Hashlib and SSL modules begin to support OpenSSL1.1.0.
6, the Hashlib module began to support the new hash algorithm, such as BLAKE2, SHA-3 and SHAKE.
7, the FileSystem and console default encoding on Windows is changed to UTF-8.
8, the Json.load () and json.loads () functions in the JSON module begin to support binary type input.
9 、.......
There are a lot of other features in the
, but that's about as much as you can use in your normal work. Interested readers can refer directly to the official documentation: What's New in Python 3.6