Python 的可變預設參數為什麼會累積
用 list 或 dict 當函式的預設參數值,資料會跨呼叫累積,因為預設值在 def 執行時就算好一次並掛在函式物件上。本文示範現象、用 __defaults__ 驗證,並給出 None 哨兵修法。
用 list 或 dict 當函式的預設參數值,資料會跨呼叫累積,因為預設值在 def 執行時就算好一次並掛在函式物件上。本文示範現象、用 __defaults__ 驗證,並給出 None 哨兵修法。
is 比對物件身分,== 比對值。小整數快取讓某些整數上兩者剛好一致,但那是不保證的 CPython 實作細節,整數值該用 == 比。
A browser-based JSON formatter that prettifies, minifies, and points to the exact line and column where a payload won't parse — all in your browser. Plus the cases where jq or python -m json.tool is all you need.
介紹 Python 內建除錯工具 pdb 的三種使用方式:命令列直接執行、設定斷點以及 Python shell 中使用 pdb.pm(),讓你告別 print 除錯法。