inside the function "bigger()", it has returned a value--a or b. so, why do still need "return"s before "bigger()"s in the function "median()"?
<p>inside the function "bigger()", it has returned a value--a or b. 
so, why do still need "return"s before "bigger()"s in the function "median()"?
Here is the code:</p>

<pre><code>def bigger(a,b):
    if a &gt; b:
        return a
    else:
        return b

def biggest(a,b,c):
    return bigger(a,bigger(b,c))

def median(a,b,c):   
    if a == biggest(a,b,c):
        return bigger(b,c)     #the function "bigger()" above has returned a value,
                           #so, why still need a 'return' before bigger(b,c)?
    elif b == biggest(a,b,c):
        return bigger(a,c)
    else:
        return bigger(a,b)
</code></pre>

<p>A function call is an expression. Consider the following:</p>

<pre><code>def add(a, b):
    a + b

x = add(3, 5)
</code></pre>

<p>Would you expect <code>x</code> to now have the value <code>8</code>? You shouldn't because <code>add</code> did not return the value of the expression <code>a+b</code>. The correct definition would be</p>

<pre><code>def add(a, b):
    return a+b
</code></pre>

<p>Now consider this function:</p>

<pre><code>def backwards_add(a, b):
    add(b, a)

x = backwards_add(3, 5)
</code></pre>

<p>Again, would you expect that <code>x</code> has the value <code>8</code>? Once again, you shouldn't because <code>backwards_add</code> did not return the value of the expression <code>add(b, a)</code>. The correct definition is</p>

<pre><code>def backwards_add(a, b):
    return add(b, a)
</code></pre>

<p>There are some languages that implicitly return the value of the last expression executed in a function (cf. Perl</p>

<pre><code>sub add {
    $1 + $2;
}
my $x = add(3, 5);  # x has the value 8
</code></pre>

<p>), but Python is not one of those languages. You must explicitly return a value, or it will return <code>None</code> for you.</p>

python return