歷代 Python 語法重點隨筆
紀錄 Python 每一代新出值得注意的新語法,持續更新
3.11
文件還在寫,目前看起來主要是效能上的改進
3.10
1 | with (CtxManager() as example): |
終於有 switch 了,讚讚1
2
3
4
5
6
7
8
9
10
11
12def 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"1
2
3
4def square(number: int | float) -> int | float:
return number ** 2
isinstance(1, int | str)
3.9
Type Hinting Generics In Standard Collections
再也不用 import typing
- before
1
2
3from typing import List
def greet_all(names: List) -> None:
# your code here - after
1
2def greet_all(names: list[str]) -> None:
# your code here
3.8
https://docs.python.org/3/whatsnew/3.8.html
支援象牙符號,