vars()和__dict__是相同的吗?

huangapple go评论102阅读模式
英文:

Is vars() same as __dict__?

问题

vars() 是一个内置函数,返回类、模块或对象的 __dict__ 属性。但是,当我检查 vars(Person) is Person.__dict__ 时,它返回 FalsePerson 是类的名称)。

英文:

I read that vars() is a built-in that returns the __dict__ attribute of class, module or object. But when I checked for vars(Person) is Person.__dict__, it returned False(Person is the name of class).

  1. class Person:
  2. def __init__(self, name, age):
  3. self.name = name
  4. self.age = age
  5. vars(Person) is Person.__dict__ # False
  6. </details>
  7. # 答案1
  8. **得分**: 4
  9. Classes create a new mappingproxy on every `__dict__` access. You would see the exact same results from `Person.__dict__ is Person.__dict__`.
  10. <details>
  11. <summary>英文:</summary>
  12. Classes create a new mappingproxy on every `__dict__` access. You would see the exact same results from `Person.__dict__ is Person.__dict__`.
  13. </details>

huangapple
  • 本文由 发表于 2023年6月8日 02:26:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76426124.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定