In Python, everything is Object (object), and objects have many properties (Arrtribute)
2 Types of attributes
Class attribute (class attribute): Class itself defines or inherits
Object attribute: The object instance defines the
Reserved properties: (= Object properties??) )
>>> Class1.__doc__ #type help information ' Class1 Doc. '>>> Class1.__name__ #type name ' Class1 '>>> Class1.__module__ #type module ' __main__ '>>> Class1.__bases__ #The base class that the type inherits from (<type ' object ');>>> Class1.__dict__ #a type dictionary that stores all type member information. <dictproxy object at 0x00d3ad70>>>> Class1 ().__class__ #type <class ' __main__. Class1 ' >>>> Class1 ().__module__ #instance type module ' __main__ '>>> Class1 ().__dict__ #Object dictionary that stores all instance member information. {' I ': 1234}
The properties of the object??? (The sense that the tutorial was written incorrectly, should be a class attribute) is stored in the object's __dict__ property. __dict__ is a dictionary, the key is the property name, and the corresponding value is the property itself.
classBird:#Bird Parent classHave_feater=true#property ' Have_feater ': Trueway_of_reproduction="Egg" #attribute ' way_of_reproduction ': ' Egg 'song="Twitter" #attribute ' song ': ' Twitter ' defSing (self):#' Sing ': <function bird.sing at 0x0000000001f0bb70> Print(Self.song)defMove (self):#' move ': <function bird.move at 0x0000000001f0bbf8> Print(" Fei Fei Fei")#attribute ' __weakref__ ': <attribute ' __weakref__ ' of ' Bird ' Objects>#attribute ' __doc__ ': None,#attribute ' __dict__ ': <attribute ' __dict__ ' of ' Bird ' Objects>#property ' __module__ ': ' __main__classChicken (Bird):#Birds Sub-categorysong="oooooo" #attribute ' song ': ' Oooooo ' def __init__(self,name):#property ' __init__ ': <function chicken.__init__ at 0x0000000001f0bc80>Self.name=namedefMove (self):#property ' move ': <function chicken.move at 0x0000000001f0bd08> Print(" Run, run, run.")#attribute ' __doc__ ': None,#attribute ' __module__ ': ' __main__ 'Mychicken=chicken ("QQ")#property ' name ': ' QQ '#If you have only the object name, you can get the class by __class__, and then __base__ get the parent classPrint(Mychicken.__class__.__base__)Print(Bird.__dict__)Print(Chicken.__dict__)Print(Mychicken.__dict__)
"Python" property