【发布时间】:2014-08-11 02:28:35
【问题描述】:
经过一番搜索后,我找不到任何涵盖此内容的示例。但我可能没有使用正确的术语,因为我对这种情况感到困惑,甚至问这是否有意义?所以我觉得这可能是重复的。
但是,如果你有一个 Python 类,其中有两个方法具有同名的参数,那么它的行为是什么?
class Foo():
def __init__(self, arg1=1, arg2=2):
def methodOne(self, amount, setting=None, extra=0):
def methodTwo(self, amount, setting=None):
...
#What is going on with setting here? What is setting referring to?
self.methodOne(amount, setting=setting)
【问题讨论】:
-
@John1024 self 是在我正在查看的代码中定义的,忘了说,我更新了问题。
标签: python variables scope default-parameters default-arguments