Python 3.9 is coming... Exciting time

ztenv 2020-11-13 12:59:55
python coming... coming exciting time

This paper mainly introduces Python3.9 Some new features of , Such as : Faster process releases , Performance improvement , Simple new string function , Dictionary union operator and more stable internal API, Detailed as follows :

  • Dictionary Union and iterative update

  • String method

  • Type tips

  • New mathematical functions

  • The new parser

  • IPv6 Address in range

  • New modules : Regional information

  • Other language changes

1、 Dictionary Union and iterative update

          Python 3.9 dict class . If there are two dictionaries a and b, You can now use these operators to merge and update .

We have merge operators |:


Use Iterables Update dictionary

| = Another great performance of the operator is the ability to use iteratable objects ( Such as lists or generators ) Update the dictionary with new key value pairs :

a = {'a': 'one', 'b': 'two'}
b = ((i, i**2) for i in range(3))
a |= b
{'a': 'one', 'b': 'two', 0: 0, 1: 1, 2: 4}

2、 String method

removeprefix() and removesuffix()

str.removeprefix(substring:string) String method : If str If you start with it , Will return a new string with modified prefix , Otherwise, it will return the original string .

str.removesuffix(substring:string) String method : If str End with it , Returns a new string with a modified suffix , Otherwise, it will return the original string .


The operations performed by these two functions will use string [len(prefix):] As a prefix ,string [:-len(suffix)] As a suffix .

These are very simple operations , So it's also a very simple function , But considering that these operations may be performed frequently , It's better to have a built-in function to do this .

3、 Type tips

Python Is dynamic , Dynamically assign data types to variables , That means we don't have to specify the data type in the code .

But sometimes it can cause confusion !

For static allocation of data types , Type hints are usually used . This is Python 3.5 Introduced in . from 3.5 Start , We can specify the type , But this is more troublesome .

This update really changed that , Now you can set the built-in collection type (List and Dict) Used as a generic type .

Before , The uppercase type must be called by input List and Dict.

ef greet_all(names: list[str]) -> None:
for name in names:
print("Hello", name)

Now? , No need to typing.List To call List

4、 New mathematical functions

The math module adds and improves many auxiliary functions , Start with improvements to existing features .


import math#Greatest common divisormath.gcd(80, 64, 152)#8

Previously used to calculate the greatest common factor gcd Function can only be applied to 2 A digital , Forcing programmers to do something like math.gcd(80,math.gcd(64,152)) The operation of . from Python 3.9 Start , We can apply it to any number of values .

math The first new addition to the module is math.lcm function :

#Least common multiple
math.lcm(4, 8, 5)

math.lcm Calculate the least common multiple of its parameters . And GCD equally , It allows a variable number of parameters .

5、 The new parser

This part is more of a change out of sight , But it could be Python One of the most significant changes in the future .

Python 3.9 A new one based on PEG The parser . before Python Use LL(1), When building new features of the language ,PEG Than LL(1) More flexible . Official documents say , This flexibility will be in Python 3.10 And later .

ast The module uses a new parser , And produce the same as the old parser AST.

6、IPv6 Address in range

Python 3.9 The other One change is You can specify IPv6 Address range .IPv6 The scope is used to specify the corresponding IP The address in Internet Which part of is effective .

Scope can be used % The sign is in IP The end of the address specifies —— for example :3FFE:0:0:1:200:F8FF:FE75:50DF%2—— So it's time to IP The address is in the range 2 in , Link to local address .

therefore , If needed Python Handle IPv6 Address , Now you can do this :

from ipaddress import IPv6Address
addr = IPv6Address('ff02::fa51%1')
#"1" - interface-local IP address

7、 New modules : Regional information

Regional information

zoneinfo The module will IANA The support of time zone database is introduced into standard database . It adds zoneinfo.ZoneInfo, This is a specific datetime.tzinfo Realization .


8、 Other language changes

__import __() Now it's added ImportError To replace ValueError, Usually occurs when a relative Import exceeds its top-level package .

“” .replace(“”,s,n) Now for all nonzero n return s Instead of empty strings . Now it's with ““ .replace(”“,s) Consistent .

By default ,Python Faster and faster

Python Each revision of has performance improvements compared to previous versions of .Python 3.9 Two major improvements have been made , Performance can be improved without any changes to existing code .

The first is more about the use of vector call protocols , Many common function calls are made by minimizing or eliminating temporary objects .Python 3.9 Several new built-in functions have been introduced , Include range、tuple、set、frozenset、list、dict —— Use vectorcall Can speed up execution .

Python Switch to annual release cycle

up to now ,Python Have already used 18 Months of development and release .PEP 602 proposal Python The development team uses an annual release cycle , And the proposal has been accepted .



  1. 利用Python爬虫获取招聘网站职位信息
  2. Using Python crawler to obtain job information of recruitment website
  3. Several highly rated Python libraries arrow, jsonpath, psutil and tenacity are recommended
  4. Python装饰器
  5. Python实现LDAP认证
  6. Python decorator
  7. Implementing LDAP authentication with Python
  8. Vscode configures Python development environment!
  9. In Python, how dare you say you can't log module? ️
  10. 我收藏的有关Python的电子书和资料
  11. python 中 lambda的一些tips
  12. python中字典的一些tips
  13. python 用生成器生成斐波那契数列
  14. python脚本转pyc踩了个坑。。。
  15. My collection of e-books and materials about Python
  16. Some tips of lambda in Python
  17. Some tips of dictionary in Python
  18. Using Python generator to generate Fibonacci sequence
  19. The conversion of Python script to PyC stepped on a pit...
  20. Python游戏开发,pygame模块,Python实现扫雷小游戏
  21. Python game development, pyGame module, python implementation of minesweeping games
  22. Python实用工具,email模块,Python实现邮件远程控制自己电脑
  23. Python utility, email module, python realizes mail remote control of its own computer
  24. 毫无头绪的自学Python,你可能连门槛都摸不到!【最佳学习路线】
  25. Python读取二进制文件代码方法解析
  26. Python字典的实现原理
  27. Without a clue, you may not even touch the threshold【 Best learning route]
  28. Parsing method of Python reading binary file code
  29. Implementation principle of Python dictionary
  30. You must know the function of pandas to parse JSON data - JSON_ normalize()
  31. Python实用案例,私人定制,Python自动化生成爱豆专属2021日历
  32. Python practical case, private customization, python automatic generation of Adu exclusive 2021 calendar
  33. 《Python实例》震惊了,用Python这么简单实现了聊天系统的脏话,广告检测
  34. "Python instance" was shocked and realized the dirty words and advertisement detection of the chat system in Python
  35. Convolutional neural network processing sequence for Python deep learning
  36. Python data structure and algorithm (1) -- enum type enum
  37. 超全大厂算法岗百问百答(推荐系统/机器学习/深度学习/C++/Spark/python)
  38. 【Python进阶】你真的明白NumPy中的ndarray吗?
  39. All questions and answers for algorithm posts of super large factories (recommended system / machine learning / deep learning / C + + / spark / Python)
  40. [advanced Python] do you really understand ndarray in numpy?
  41. 【Python进阶】Python进阶专栏栏主自述:不忘初心,砥砺前行
  42. [advanced Python] Python advanced column main readme: never forget the original intention and forge ahead
  43. python垃圾回收和缓存管理
  44. java调用Python程序
  45. java调用Python程序
  46. Python常用函数有哪些?Python基础入门课程
  47. Python garbage collection and cache management
  48. Java calling Python program
  49. Java calling Python program
  50. What functions are commonly used in Python? Introduction to Python Basics
  51. Python basic knowledge
  52. Anaconda5.2 安装 Python 库(MySQLdb)的方法
  53. Python实现对脑电数据情绪分析
  54. Anaconda 5.2 method of installing Python Library (mysqldb)
  55. Python implements emotion analysis of EEG data
  56. Master some advanced usage of Python in 30 seconds, which makes others envy it
  57. python爬取百度图片并对图片做一系列处理
  58. Python crawls Baidu pictures and does a series of processing on them
  59. python链接mysql数据库
  60. Python link MySQL database