letter Q
letter Q

Reputation: 15385

Python method parameter list

in a method definition why would someone set the formal parameter amount equal to the constant PERMANENCE_INC in the formal parameter list?

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

Upvotes: 1

Views: 128

Answers (2)

Jari
Jari

Reputation: 2152

That gives default value for the parameter in case it is not provided when the function is called.

For example, to increase permanence by default value, you would call:

obj.increasePermanence()

Upvotes: 2

Howard
Howard

Reputation: 39197

This form makes amount an optional argument with a default value of PERMANENCE_INC.

Upvotes: 0

Related Questions