Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why keyword `match` in Python 3.10 can be as a variable or function name? [duplicate]

I don't fully understand why the keyword match can be used as a variable or function name, unlike other keywords 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'
like image 660
Be3y4uu_K0T Avatar asked Sep 03 '26 19:09

Be3y4uu_K0T


1 Answers

Per PEP 622, match and case are being added as "soft keywords", so they will remain valid identifiers:

This PEP is fully backwards compatible: the match and case keywords are proposed to be (and stay!) soft keywords, so their use as variable, function, class, module or attribute names is not impeded at all.

like image 157
Brian Avatar answered Sep 06 '26 08:09

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!