--- tags: blog --- # python 筆記 每一代新出值得注意的新語法筆記一下 ## 3.11 > 文件還在寫,目前看起來主要是效能上的改進 ## 3.10 ```python= with (CtxManager() as example): ... with ( CtxManager1(), CtxManager2() ): ... with (CtxManager1() as example, CtxManager2()): ... with (CtxManager1(), CtxManager2() as example): ... with ( CtxManager1() as example1, CtxManager2() as example2 ): # 變成 with ( CtxManager1() as example1, CtxManager2() as example2, CtxManager3() as example3, ): ``` > 終於有 switch 了 > [name=CodingMan][time=Fri, Oct 29, 2021 3:54 PM] ```python= def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case 401 | 403: return "qqqqq" case _: return "Something's wrong with the internet" ``` ```python= def square(number: int | float) -> int | float: return number ** 2 isinstance(1, int | str) ``` ## 3.9 ### Type Hinting Generics In Standard Collections > 再也不用 import typing > [name=CodingMan] - before ```python= from typing import List def greet_all(names: List) -> None: # your code here ``` - after ```python= def greet_all(names: list[str]) -> None: # your code here ``` ## 3.8