我想從類中調用另一種方法創建的某個方法。我將如何做到這一點?從同一個類中的另一個方法創建的某個類調用一個方法?
例如,我剛剛創建了一個名爲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' –