為何在 Python 中不鼓勵使用「id」作為變數名稱?
在 Python 中應該避免命名變數 id。這是因為 id() 是一個完整的內建函數,它為系統記憶體中的物件提供唯一識別碼。
help(id)
# Output
Help on built-in function id in module __builtin__:
id(...)
id(object) -> integer
Return the identity of an object. This is guaranteed to be unique among
simultaneously existing objects. (Hint: it's the object's memory
address.)
命名變數 id 可能會導致與內建函數的命名衝突。因此,通常建議避免使用關鍵字或內建函數名稱作為變數名稱。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3