[Python] 確認某變數/函式/方法是否已定義

locals() -> dict Listing variables in local scope.
globals() -> dict Listing variables in global scope (current module namespace).
dir([object]) -> list[str]
  • dir(): Listing all names(variables, function, class, module, … etc.).
  • dir(object): Listing attributes and methods in the object.
vars([object]) -> dict
  • vars() ≡ locals()
  • vars(object) ≡ object.__dict__

Last Updated on 2025/05/12 by A1go

Bitnami