Function Calling Python basic
<p>I'm trying to enter values from the tuple <code>('a',1), ('b',2),('c',3)</code> into the function <code>dostuff</code> but i always get a return of <code>None</code> or <code>False</code>. i'm new to this to i'm sorry if this question is basic. I would appreciate any help.</p>

<p>I expect the result of this to be:</p>

<pre><code>a1---8
b2---8 
c3---8
</code></pre>

<p>Code:</p>

<pre><code>def dostuff(stri,numb,char):
        cal = stri+str(numb)+'---'+str(char)
        return cal

def callit (tups,char):
    for x in range(len(tups)):
        dostuff(tups[x][0],tups[x][1],char)

print(callit([('a',1), ('b',2),('c',3)],8))
</code></pre>

<p>For a function to return a value in python it must have a <code>return</code> statement. In your <code>callit</code> function you lack a value to <code>return</code>. A more Pythonic approach would have both a value and iterate through the tuples using something like this:</p>

<pre><code>def callit(tups, char):
    x = [dostuff(a, b, char) for a, b in tups]
    return x
</code></pre>

<p>Since <code>tups</code> is a list of tuples, we can iterate through it using <code>for a, b in tups</code> - this grabs both elements in the pairs. Next <code>dostuff(a, b, char)</code> is calling your <code>dostuff</code> function on each pair of elements and the <code>char</code> specified. Enclosing that in brackets makes the result a list, which we then return using the <code>return</code> statement. </p>

<p>Note you don't need to do:</p>

<pre><code>x = ...
return x
</code></pre>

<p>You can just use <code>return [dostuff(a, b, char) for a, b in tups]</code> but I used the former for clarity.</p>

python