我想从类中调用另一种方法创建的某个方法。我将如何做到这一点?从同一个类中的另一个方法创建的某个类调用一个方法?
例如,我刚刚创建了一个名为call me的类,并且想要使用add
方法中的subtract
方法的结果。
class call_me(object):
def __init__(self, x, y):
self.x = 5
self.y = 10
def subtract(self):
difference = self.y - self.x
return difference
def add(self.subtract,second_number):
# code to add the difference returned by subtract to the second number.
我该如何添加第二个数字来减去返回的差值?有没有办法让我通过difference
到add
?
'self.subtract()+ second_number' –