self 调用类的属性:
写个类来看看:
class human(object):
speak = 'ma name is hello'
emotion = 'I love you'
def func1(self):
self.speak = s
self.emotion = e
return s,e
Bob = human()
print(Bob.func1())
__init__初始化用法:
class black_human(human):
def __init__(self,color):
c = self.color
return c
zhangfei = black_human('black') #black_human是human的子类(继承关系),故zhangfei继承了human类,将'black'作为参数传给__init__里面的color
实际使用:
class Zhou(object): def __init__(self,a,b,c,d): self.a = a self.b = b self.c = c self.d = d def func1(self): a = self.a b = self.b a = a +'aaaaaa' b = b + 'bbbbbbb' return a,b def func2(self): c = self.c d = self.d data1,data2 = self.func1() print(data1+data2+c+d) if __name__ =='__main__': # 假设我们需要用到的参数 a,b,c,d... 这里也可以用到参数解析器模块(后续) a = 'one' b = 'two' c = 'three' d = 'four' ok = Zhou(a,b,c,d) ok.func2()