Special properties of the class /Special property of Class
In Python, classes are defined by class, and classes can be instantiated into instances and invoked using an instance.
The class also contains some common special properties.
Special class Properties |
Meaning |
__name__ |
The name of the class (string) |
__doc__ |
The document string for the class |
__bases__ |
A tuple that consists of all the parent classes of the |
__dict__ |
A dictionary of the properties of a class |
__module__ |
module to which the class belongs |
__class__ |
Type of class object |
1 classFoo ():2 """3 This is the text of the can be called by __doc__4 """5 def __init__(self):6Self.foo =None7 8 defFoo_method (self):9Self.foom =TrueTen One Print('>>>'Foo.__name__) A Print('>>>'Foo.__doc__) - Print('>>>'Foo.__bases__) - Print('>>>'Foo.__dict__) the Print('>>>'Foo.__module__) - Print('>>>'Foo.__class__)
The above code defines a Foo class and invokes the basic special properties of the class in turn, resulting in the following results.
>>>Foo>>> This isThe text that can is called by__doc__>>> (<class 'Object'>,)>>> {'__dict__': <attribute'__dict__'Of'Foo'Objects>,'__doc__':'\ n This is the text, can be called by __doc__\n','__weakref__': <attribute'__weakref__'Of'Foo'Objects>,'__init__': <function Foo.__init__At 0x0301f930>'__module__':'__main__','Foo_method': <function Foo.foo_method at 0x0305c348>}>>>__main__>>> <class 'type'>
Python's program structure [2]-Class/class-Class special properties