Python 官宣:正式发布 Python 3.8.0!

网友投稿 725 2022-05-29

来源:.python.org

编辑:肖琴,转自:新智元

PEP 572,赋值表达式

PEP 570,仅限位置形参

PEP 587,Python 初始化配置(改进的嵌入)

PEP 590,Vectorcall:用于 CPython 的快速调用协议

PEP 578, Python Runtime Audit Hooks

PEP 574,具有外部数据缓冲区的 pickle 协议 5

与打字相关:PEP 591(最终限定词),PEP 586(文学类型)和 PEP 589(TypedDict)

用于已编译字节码文件的并行文件系统缓存

调试构建使用与发布构建相同的 ABI

f - 字符串支持 = 用于自动记录表达式和调试文档

在 Windows 上,默认 asyncio 事件循环现在是 ProactorEventLoop

在 macOS 上,spawn 启动方法默认使用 multiprocessing

multiprocessing 现在可以使用共享内存段来避免进程之间的酸洗成本

typed_ast 被合并回 CPython

LOAD_GLOBAL 速度加快了 40%

pickle 现在默认使用协议 4,提高了性能

if (n := len(a)) > 10:    print(f"List is too long ({n} elements, expected <= 10)")

discount = 0.0if (mo := re.search(r'(\d+)% discount', advertisement)):    discount = float(mo.group(1)) / 100.0

# Loop over fixed length blockswhile (block := f.read(256)) != '':    process(block)

[clean_name.title() for name in names if (clean_name := normalize('NFC', name)) in allowed_names]

def f(a, b, /, c, d, *, e, f):    print(a, b, c, d, e, f)

f(10, 20, 30, d=40, e=50, f=60)

f(10, b=20, c=30, d=40, e=50, f=60)   # b cannot be a keyword argumentf(10, 20, 30, 40, 50, f=60)           # e must be a keyword argument

def pow(x, y, z=None, /):    "Emulate the built in pow() function"    r = x ** y    return r if z is None else r%z

Python 官宣:正式发布 Python 3.8.0!

len(obj='hello')  # The "obj" keyword argument impairs readability

def quantiles(dist, /, *, n=4, method='exclusive')    ...

>>> def f(a, b, /, **kwargs):...     print(a, b, kwargs)...>>> f(10, 20, a=1, b=2, c=3)         # a and b are used in two ways10 20 {'a': 1, 'b': 2, 'c': 3}

class Counter(dict):

def __init__(self, iterable=None, /, **kwds):        # Note "iterable" is a possible keyword argument

>>> user = 'eric_idle'>>> member_since = date(1975, 7, 31)>>> f'{user=} {member_since=}'"user='eric_idle' member_since=datetime.date(1975, 7, 31)"

>>> delta = date.today() - member_since>>> f'{user=!s}  {delta.days=:,d}''user=eric_idle  delta.days=16,075'

>>> print(f'{theta=}  {cos(radians(theta))=:.3f}')theta=30  cos(radians(theta))=0.866

人工智能

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:shm进程间通信失败了!!!
下一篇:使用 PyQt 的 QThread 防止冻结 GUI
相关文章