Is it OK to replace a method by a plain function?
<p>This works as expected, but I am somehow unsure about this approach. Is it safe? Is it pythonic?</p>

<pre><code>class Example:
    def __init__(self, parameter):
        if parameter == 0:
            # trivial case, the result is always zero
            self.calc = lambda x: 0.0  # &lt;== replacing a method
        self._parameter = parameter

    def calc(self, x):
        # ... long calculation of result ...
        return result
</code></pre>

<p>(If there is any difference between Python2 and Python3, I'm using Python3 only.)</p>

<p>This is very confusing. If someone else reads it, they won't understand what is going on. Just put a <code>if</code> statement at the beginning of your method.</p>

<pre><code>def calc(self, x):
    if self.parameter == 0:
         return 0
    # ... long calculation of result ...
    return result
</code></pre>

<p>Also if you change <code>self.parameter</code> after it was initialized with <code>0</code>, your function wouldn't work anymore.</p>

python