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

Be3*_*K0T 4 python pattern-matching keyword python-3.10

我不完全理解为什么关键字match可以用作变量或函数名,而不像其他关键字ifwhile等等?

>>> 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'
Run Code Online (Sandbox Code Playgroud)

Bri*_*ian 10

根据PEP 622matchcase被添加为“软关键字”,因此它们将仍然是有效的标识符:

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