其他
Python 3.10 明年发布,看看都有哪些新特性?
阅读本文大概需要 2 分钟。
推荐三个网站
1.Python进阶知识: http://python.iswbm.com
2.Python魔法技巧: http://magic.iswbm.com
3.PyCharm 手册: http://pycharm.iswbm.com
突出显示Python 3.10中的功能
(1) 二进制表示中的频率为1
>>> num = 108
# Let's first get the binary representation of num
>>> bin(num)
'0b1101100'
>>> num.bit_count()
4
# Negative integer
>>> num = -108
>>> bin(num)
'-0b1101100'
>>> num.bit_count()
4
# Under the hood
>>> bin(num).count('1')
(2) 压缩将是"严格的"
[('A', 'Apple'), ('B', 'Ball'), ('C', 'Cat')]
Traceback (most recent call last): ...ValueError: zip() argument 1 is longer than argument 2
(3) 字典的只读视图
>>> keys = fruits.keys()
>>> values = fruits.values()
>>> list(keys)
['Mangos', 'Figs', 'Guavas', 'Kiwis']
>>> del fruits['Guavas']
>>> print (list(keys), list(values))
['Mangos', 'Kiwis'] [12, 70]
>>> values.mapping
mappingproxy({'Mangos': 12, 'Figs': 100, 'Guavas': 3, 'Kiwis': 70})
>>> values.mapping['Guavas']
3
(4) 消除一些向后兼容性
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working