I want to print integer variables string separated by some string in Python3
<p>I am trying to print 3 integer variables separated by some string. But it is giving me an error </p>

<blockquote>
  <p>TypeError: unsupported operand type(s) for +: 'int' and 'str'.</p>
</blockquote>

<p>My attempt: </p>

<pre><code>def unpack_values(grades):
     first, *middle, last = grades
     avg = sum(middle)/len(middle)
     print(str(first)+"-------"+str(avg)+" ---- "+str(last))

unpack_values(['10', '20', '30', '40', '50'])
</code></pre>

<p>The error occurs when trying to calculate <code>sum(middle)</code>, because <code>middle</code> is a list of strings. You need to convert it to integers first.</p>

<pre><code>In [1]: def unpack_values(grades):
   ...:     first, *middle, last = [int(g) for g in grades]
   ...:     avg = sum(middle) / len(middle)
   ...:     print('{} ------ {} ------ {}'.format(first, avg, last))
   ...:     

In [2]: unpack_values(['10', '20', '30', '40', '50'])
10 ------ 30.0 ------ 50
</code></pre>

python python-3.x