英文:
Is vars() same as __dict__?
问题
vars()
是一个内置函数,返回类、模块或对象的 __dict__
属性。但是,当我检查 vars(Person) is Person.__dict__
时,它返回 False
(Person
是类的名称)。
英文:
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).
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
vars(Person) is Person.__dict__ # False
</details>
# 答案1
**得分**: 4
Classes create a new mappingproxy on every `__dict__` access. You would see the exact same results from `Person.__dict__ is Person.__dict__`.
<details>
<summary>英文:</summary>
Classes create a new mappingproxy on every `__dict__` access. You would see the exact same results from `Person.__dict__ is Person.__dict__`.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论