Calling a method that have return value in Python
<p>I'm new to python and came into this piece of code. From my previous programming knowledge, I'm assuming this method should return something(<code>results</code>). But why do some statements like <code>self.children[0].query(rect, results)</code> don't assign the return value to any variable while recursively calling the method?</p>

<pre><code>def query(self, rect, results=None):

    if results is None:
        rect = normalize_rect(rect)
        results = set()

    if len(self.children) &gt; 0:
        if rect[0] &lt;= self.center[0]:
            if rect[1] &lt;= self.center[1]:
                self.children[0].query(rect, results)
            if rect[3] &gt; self.center[1]:
                self.children[1].query(rect, results)
        if rect[2] &gt; self.center[0]:
            if rect[1] &lt;= self.center[1]:
                self.children[2].query(rect, results)
            if rect[3] &gt; self.center[1]:
                self.children[3].query(rect, results)

    for node in self.nodes:
        if (node.rect[2] &gt; rect[0] and node.rect[0] &lt;= rect[2] and
                node.rect[3] &gt; rect[1] and node.rect[1] &lt;= rect[3]):
            results.add(node.item)

    return results
</code></pre>

<p>You're right that the <code>query</code> function does return <code>results</code>, but it also <em>modifies</em> <code>results</code> on this line:</p>

<pre><code>results.add(node.item)
</code></pre>

<p>A parameter used in this was is sometimes described as an "output parameter".</p>

<p><code>query</code> is not a pure function. In those places where <code>query</code> is called without using its return value, <code>query</code> is being called for its side effects.</p>

python python-2.7 python-3.x