【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循环体里面。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值