python - Why do metaclass have a type? -
i've little bit test understand metaclass in python.
class test(object): pass print test.__class__ print test.__class__.__class__ print test.__class__.__class__.__class__
all of result same type
. each of address not same
can't understand why metaclass has metaclass recursively.
explain me please?
actually, addresses same:
>>> id(test.__class__) 6384576 >>> id(test.__class__.__class__) 6384576 >>> id(test.__class__.__class__.__class__) 6384576
everything object in python, , each object must have class (it should belong type). can access class/type reference __class__
attribute, e.g.:
>>> (1).__class__ <type 'int'>
everything includes classes itself, of class/type called type
:
>>> (1).__class__.__class__ <type 'type'>
in same time type 'type'>
object , should reference class/type. since kind of special object, __class__
attribute refers itself:
>>> (1).__class__.__class__.__class__ (1).__class__.__class__ true
Comments
Post a Comment