python的每一个类都有定义一些方法, 这些方法可以显式调用,也可以可以通过以下这种方式调用。
class A:
def __init__(self):
self.sample = [1,2,3]
pass
def __len__(self):
pass
def __call__(self):
pass
def __getitem__(self, item):
return self.sample[item]
def __str__(self):
pass
def __int__(self):
pass
def __iter__(self):
pass
def __next__(self):
pass
def myfunction(self):
pass
a = A()
len(a) == a.__len__()
a() == a.__call__()
next(a) == a.__next__()
a[index] == a.__getitem__(index)
str(a) == a.__str__()
int(a) == a.__int__()
next(a) == a.__next__()
A.myfunction(a) = a.myfunction()
a.sample = a.__dict__['sample'] # All the properities in one class would be stored in this dict.
`__dict__` 这个属性是几乎每一个python对象都拥有的属性,它是一个字典,存储了该对象的所有属性值。除非你创建了一个空的类。
More examples, please see https://docs.python.org/3/library/collections.abc.html