__init__
()d的作用
init()方法是一个特殊的方法,在对象实例化时会被调用,init()方法的作用是初始化参数
每当创建一个类的实例对象时,Python 解释器都会自动调用它
必须包含一个名为 self 的参数,且必须作为第一个参数
例子:
class Te:
def __init__(self):
self.x1 = 100
def nice(self, a):
self.A = a
return self.A + str(self.x1)
ta = Te()
print(ta.nice('to'))
输出
to100