Python 3.10 is Released - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: Python 3.10 is Released (/thread-35187.html) |
Python 3.10 is Released - snippsat - Oct-07-2021 Release Python 3.10.0 One big new thing is the new switch/case statements version on steroid💪 It's called Structural Pattern Matching A quick test: vehicle = 'Taxi' match vehicle: case 'Car': print('Drive yourself') case 'Bus'|'Taxi': print('Public transport') case _: print(f'{vehicle!r} not in record'
status_code = 200 match status_code: case 400|401|403 : print("Bad request") case 200: print("Request Ok") case _: print("Something else bad happened") So as excepted and | is used as as or pattern.A nice short way to specify an isinstance() check.my_string = 'Hello' #my_string = 5 match my_string: case int(): print("I'm a integer") case str(): print("I'm a string")
Better error messages >>> lst = [1, 2, 3 File "<stdin>", line 1 lst = [1, 2, 3 ^ SyntaxError: '[' was never closed >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized def foo(): if pin: x = 2 else: x = 100 Advice when error,eg typo ect...>>> liist('hello') Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'liist' is not defined. Did you mean: 'list'? >>> list('hello') ['h', 'e', 'l', 'l', 'o'] >>> from datetime import date >>> >>> data(2020, 5, 17)) File "<stdin>", line 1 data(2020, 5, 17)) ^ SyntaxError: unmatched ')' >>> data(2020, 5, 17) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'data' is not defined. Did you mean: 'date'? >>> date(2020, 5, 17) datetime.date(2020, 5, 17) RE: Python 3.10 is Released - Yoriz - Oct-07-2021 YouTube - Python 3.10 Release Stream — with Pablo Galindo |