为什么Python 3.10中的关键字“match”可以作为变量或函数名? [复制]

2023-11-29

我不完全明白为什么这个关键字match与其他关键字不同,可以用作变量或函数名称if, while, etc.?

>>> match "abc":
...     case "abc":
...         print('Hello!')
...     
Hello!
>>> from re import match
>>> match('A', 'A Something A')
<re.Match object; span=(0, 1), match='A'>
>>> match = '????'
>>> match
'????'
>>> case = 'something'
>>> case
'something'

Per PEP 622, match and case正在添加为“软关键词”,因此它们将保持有效的标识符:

此 PEP 完全向后兼容:match and case关键字被建议为(并且保持!)软关键字,因此它们用作变量、函数、类、模块或属性名称完全不受阻碍。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么Python 3.10中的关键字“match”可以作为变量或函数名? [复制] 的相关文章

随机推荐