Python may get pattern matching syntax
The creators of the Python language are mulling a new proposal, PEP 622, that would finally bring a pattern matching statement syntax to Python. The new pattern matching statements would give Python programmers more expressive ways of handling structured data, without having to resort to workarounds. Pattern matching is a common feature of many programming languages, such as switch/case in C. It allows one of a number of possible actions to be taken based on the value of a given variable or expression. While Python has lacked a native syntax for pattern matching, it has been possible to emulate it with if/elif/else chains or a dictionary lookup. Supported pattern match types include literals, names, constant values, sequences, a mapping (basically, the presence of a key-value pair in the expression), a class, a mixture of the above, or any of those plus conditional expressions.
Jun-28-2020, 11:45:44 GMT
- Technology: