Tag: Set ATT value technology performs operation BSP subclass attr
Object-oriented built-in methods (example)
I, Isinstance (OBJ,CLS) and Issubclass (Sub,super)
1. Check if BoJ is an object (instance)
class Foo (object): Pass = Foo ()print(isinstance (obj, Foo))
determine who the object is (instance)
2. Check if sub is sub-class
class Foo (object): Pass class Sub (Foo): Print ('sub'= foo () Issubclass (Bar, foo)
judge who the class is
Item Series-The object is made into something like a Dictionary object, allowing the operator to manipulate things like objects.
classFoo:def __init__(self, name): Self.name=namedef __getitem__(self, item):Print(self.)__dict__[item])def __setitem__(self, Key, value): Self.__dict__[Key] =valuedef __delitem__(self, key):Print('del Obj[key] when I executed the') self.__dict__. Pop (key)def __delattr__(self, item):Print('del Obj.key when I do') self.__dict__. Pop (item) F1= Foo ('SB') f1[' Age'] = 18f1['Age1'] = 19delF1.age1delf1[' Age']f1['name'] ='Alex'Print(F1.__dict__)make a custom object into a Dictionary object
Third, __str__ (the property in the class is customized to the STR user to print the object, the information is returned to the user)
class people: def __init__ (self,name,age): Self.name = name self.age = age Span style= "COLOR: #0000ff" >def __str__ ( Self): return " <name>:%s <age>:%s " % (self.name,self.age) P1 = people ( " alex ", 12) print (p1)
class properties are custom-made into strings
Iv. __del__ (Recycling resources)
class Foo: def __del__ print ( " execute me " ) F1 =foo () # del F1 print (" -------; " ) # output # -------; # execute me
(Destruction method) Recycling resources
python-Object-oriented programming-built-in methods