Why does Python call both functions?
<p>I have some problems to understand what happens here.</p>

<p>This is my source:</p>

<pre><code>class Calc():

    def __init__(self,Ideal,Limit,Value,Debug=None):

        self.Ideal = Ideal
        self.Limit = Limit
        self.Value = Value
        self.Debug = Debug
        self.Grade = self.GetGrade()
        self.LenGrade = self.GetLenGrade()

    def GetGrade(self):
        if self.Debug:
            print('calling GetGrade')
        return Grade

    def GetLenGrade(self):
        if self.Debug:
            print('calling GetLenGrade')
        return Grade
</code></pre>

<p>When calling it with</p>

<pre><code>GradeMinLen += Calc(TargetLen, LimitMinLen, Length ,Debug=1).LenGrade
</code></pre>

<p>I get always the output</p>

<pre><code>calling GetGrade    
calling GetLenGrade
</code></pre>

<p>Why is python calling <code>GetGrade</code>?</p>

<p>In your object initialisation code, you have the following:</p>

<pre><code>self.Grade = self.GetGrade()
self.LenGrade = self.GetLenGrade()
</code></pre>

<p>This means "set the value of the data member Grade to the value obtained by calling the method GetGrade" and the same for LenGrade.</p>

<p>It should not be surprising that they're called, it would be more surprising if they were not.</p>

python