__new__(cls [,...]) |
instance = MyClass(arg1, arg2) |
__new__ is called when instance is created |
__init__(self [,...]) |
instance = MyClass(arg1, arg2) |
__init__ is called when instance is created |
__cmp__(self, other) |
self == other, self > other, 等。 |
Call when comparing |
__pos__(self) |
+self |
Unary plus operator |
__neg__(self) |
-self |
Unary minus operator |
__invert__(self) |
~self |
Negation operator |
__index__(self) |
x[self] |
When an object is used as an index used |
__nonzero__(self) |
bool(self) |
Boolean value of the object |
__getattr__(self, name) |
self.name # name does not exist |
When accessing a nonexistent property |
__setattr__(self, name, val) |
self.name = val |
For when a property assignment |
__delattr__(self, name) |
of the self.name |
When delete a property |
__getattribute(self, name) |
self.name |
When access to any property |
__getitem__(self, key) |
self[key] |
When you use an index to access elements |
__setitem__(self, key, val) |
self[key] = val |
When assigning an index value |
__delitem__(self, key) |
del self[key] |
When delete an index value |
__iter__(self) |
for x in self |
Iteration |
__contains__(self, value) |
value in self, value not in self |
When using the test operation in relation |
__concat__(self, value) |
self + other |
When connecting two objects |
__call__(self [,...]) |
self(args) |
When the "call" Object |
__enter__(self) |
with self as x: |
with environmental management statement |
__exit__(self, exc, val, trace) |
with self as x: |
with environmental management statement |
__getstate__(self) |
pickle.dump(pkl_file, self) |
Serialization |
__setstate__(self) |
data = pickle.load(pkl_file) |
Serialization |