PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

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

 July 09, 2022     keyword, pattern-matching, python, python-3.10     No comments   

Issue

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'

Solution

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.



Answered By - Brian
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing