Python

Python 的可變預設參數為什麼會累積

用 list 或 dict 當函式的預設參數值,資料會跨呼叫累積,因為預設值在 def 執行時就算好一次並掛在函式物件上。本文示範現象、用 __defaults__ 驗證,並給出 None 哨兵修法。

2026-07-23 · 3 min read · 1021 words · KbWen · ZH
Python

Python 的 is 和 == 差在哪

is 比對物件身分,== 比對值。小整數快取讓某些整數上兩者剛好一致,但那是不保證的 CPython 實作細節,整數值該用 == 比。

2026-07-20 · 3 min read · 1132 words · KbWen · ZH
JSON formatter: format, validate, and debug JSON
Python

JSON formatter: format, validate, and debug JSON

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.

2026-07-11 · 3 min read · 517 words · KbWen · EN
python pdb
Python

python pdb

介紹 Python 內建除錯工具 pdb 的三種使用方式:命令列直接執行、設定斷點以及 Python shell 中使用 pdb.pm(),讓你告別 print 除錯法。

2020-04-10 · 1 min read · 396 words · KbWen · ZH