p.__dict__
p.__class__
result:------
1
2
{'__module__': '__main__', '__doc__': None}
{'y': 2, 'x': 1}
__main__.point
------
comments:
1.this shows how class and instance be created
2.note that class might have no attribute at first,
we can add attribute latter.
3.__dict__ is the inherent attribute of class and instance,
all attributes of class and instance are stored in __dict__
4.__class__ is the inherent attribute of an instance,
the class name of the instance is stored in it
example code2:
class
point
:
def
__init__
(
self
):
self
.x=
1
self
.y=
2
p=point()
p.x
p.y
point.__dict__
p.__dict__
p.__class__
dir(p)
result:------
1
2
{'__module__': '__main__', '__doc__': None,
'__init__':
__init__ at
0x022BE2F0>}
{'y': 2, 'x': 1}
__main__.point
['__doc__', '__init__', '__module__', 'x', 'y']
------