1, no permission control, before the class method or variable with "__" two underscores, then become "private" variable (actually through the _< class name >__< variable or method name > can be accessed)
2, the class of several automatic triggering of the built-in method:
- __new__ (cls[, ...]) The method returns an instance of this class, passing the passed parameters to the __init__ () method intact. This method is typically used when inheriting a class that is not modifiable, such as Str
Class Capstr (str):
Def __new__ (CLS, string):
string = String.upper ()
Return str.__new__ (CLS, String)
A = Capstr ("I Love You");
- __init__ (self[, ...]) The method is called the first time after the instance is created to initialize the object
Class Rectangle:
def __init__ (self, x, y):
self.x = X
Self.y = y
def getperi (self):
Return (self.x + self.y) * *
Aa=rectangle (3, 4);
Aa.getperi ()
- __del__ (self) //This method is triggered when the class instance is freed and finally garbage collected
C1=c ()
C2=c1
C3=c2
del C3//will not be triggered
Del C2//will not be triggered
Del C1//All references eliminated, triggering __del__
- __ADD__ (Self,other)//Two classes are added when a trigger
- __SUB__ (Self,other)//Two classes are subtracted when triggered
- __MUL__ (self,other)//Multiply Trigger
- __TRUEDIV__ (Self,other)//True Division
Python Learning (II.)--about class