Python方法参数lis

2024-09-26 18:19:48 发布

您现在位置:Python中文网/ 问答频道 /正文

在方法定义中,为什么有人要将形式参数amount设置为形式参数列表中的常量PERMANENCE_INC?你知道吗

def increasePermanence(self, amount=PERMANENCE_INC): 
    """ Increases the permanence of this synapse. """ 
    self.permanence = min(1.0, self.permanence+amount)

Tags: ofthe方法self列表定义defthis
2条回答

此窗体使amount成为一个可选参数,默认值为PERMANENCE_INC。你知道吗

如果在调用函数时未提供参数,则为参数提供默认值。你知道吗

例如,要按默认值增加持久性,可以调用:

obj.increasePermanence()

相关问题 更多 >

    热门问题