【发布时间】:2017-12-17 08:58:08
【问题描述】:
在学习 Python 和一般编程时,我遇到了一个我不太确定的概念。我正在编写一个脚本,我很好奇我是否已经创建了对象,如果我想从该对象的方法之一访问返回的值,它会重新运行该方法,还是简单地回复这些值。例如:
class ClassOne():
def oneMethod(self):
x = 2
y = 10
return x, y
class ClassTwo():
def twoMethod(self, x, y):
...
newObject = ClassOne()
newObject.oneMethod()
secondObject = ClassTwo()
# My question is, will the lines below re-execute newObject.oneMethod()
# or will it simply pull the already returned value
secondObject.twoMethod(newObject.oneMethod()[0],
newObject.oneMethod()[1])
虽然我的脚本不一定大到足以担心性能问题,但这只是我想知道的,在网上找不到太多信息。
【问题讨论】:
标签: python python-3.x class methods