Python3新特性
1、f-strings(3.6+)
first="001"
second="002"
test_msg = f'this is first {first}, this is second {second}.'
print(test_msg)
this is first 001, this is second 002.
2、Type hinting(3.5+)
def abc(a: str) -> bool:
return a in 'this is a msg'
abc('is')
3、字典顺序得到保证
>>> {"abc": 1, "abd": 3, "abe": 2}
{'abc': 1, 'abd': 3, 'abe': 2}
4、跨进程内存共享
在multiprocessing添加了一个shared_memory模块,支持跨进程间的内存共享。
5、字典合并
old:
dict(x, **y)
new:
{**x, **y}
6、列表推导式优化
# old:
>>> x = 1
>>> [x for x in "abc"]
['a', 'b', 'c']
>>> x # x 变量被推导式修改
'c'
# new
>>> x = 1
>>> [x for x in "abc"]
['a', 'b', 'c']
>>> x # x 变量被推导式修改
1