【python】python3.8的新特性

What’s New In Python 3.8
python3.8的新特性

Editor Raymond Hettinger
编辑 Raymond Hettinger

This article explains the new features in Python 3.8, compared to 3.7. For full details, see the changelog.
这篇文章对比与python3.7阐述了python3.8的新特性。关于全部详情,请查看更新日志。

Python 3.8 was released on October 14th, 2019.
Python 3.8 发布于 2019年10月14日

Summary – Release highlights
概要 发布亮点

New Features
新特性

Assignment expressions
赋值表达式

There is new syntax := that assigns values to variables as part of a larger expression. It is affectionately known as “the walrus operator” due to its resemblance to the eyes and tusks of a walrus.
新增一个语法:=它分配值给变量作为更大表达式中的一部分。由于它和海象的眼睛和长牙相似,它被亲切地称为海象运算符。

In this example, the assignment expression helps avoid calling len() twice:
在这个例子中,这个赋值表达式能够避免调用两次len():

A similar benefit arises during regular expression matching where match objects are needed twice, once to test whether a match occurred and another to extract a subgroup:
一个相似的好处产生在正则表达式匹配对象两次的时候,一个是去测试是否匹配发生,另一个是提取子类。

The operator is also useful with while-loops that compute a value to test loop termination and then need that same value again in the body of the loop:
对于使用while-loop循环的操作也是有用的,它能计算一个值去测试循环结束然后再次需要相同的值在loop循环体里面。

发布了82 篇原创文章 · 获赞 468 · 访问量 24万+

猜你喜欢

转载自blog.csdn.net/qq_44647926/article/details/102576288