[英]Call a method from a class on something created by a different method in the same class?
我想從類中的方法調用類中的另一個方法創建的東西。 我該怎么做?
例如,我剛剛創建了一個名為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.
如何將第二個數字加到減法返回的差值中? 有什么辦法可以add
difference
嗎?
def add(self, second_number):
difference = self.substract()
return difference + second_number
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.