Can I include a for loop inside my print statement?
<p>I have a list of winners of an event. I want to print them out at the end of my code, minus the brackets and quotes, and I am currently using:</p>

<pre><code>            for items in winners:
                print(items)
</code></pre>

<p>Can I include this in a print statement?
I want:</p>

<pre><code>            print("The winners of {} were: {} with a score of {}".format(sport, winners, max_result))
</code></pre>

<p>Is there a way of integrating the for loop into the print statement, or another way of eliminating the quotes and square brackets such that I can include it in the statement?</p>

<p>Thanks.</p>

<p>If <code>winners</code> is a list of strings, you can concatenate them using <code>str.join</code>.</p>

<p>For example:</p>

<pre><code>&gt;&gt;&gt; winners = ['John', 'Jack', 'Jill']
&gt;&gt;&gt; ', '.join(winners)
'John, Jack, Jill'
</code></pre>

<p>So you can put <code>', '.join(winners)</code> in your print call instead of <code>winners</code> and it will print the winners separated by commas.</p>

python python-3.x