类内函数的调用
class A():
def double(self,x):
return x*2
def triple(self,y):
return y*3
def sum(self,x,y):
return self.double(x)+self.triple(y)
if __name__ == '__main__':
print(A().sum(5,6))
结果为:28
类间函数的调用
class A():
def double(self,x):
return x*2
def triple(self,y):
return y*3
class B(A):
def sum(self,x,y):
return super().double(x)+super().triple(y)
if __name__ == '__main__':
print(B().sum(5,6))
定义类 class A:
,class A():
,class A(object)
这三种没有区别。
可以通过dir()
查询属性
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'double', 'sum', 'triple']
标签:__,return,triple,类间,Python,self,类内,class,def
From: https://www.cnblogs.com/conpi/p/17162144.html