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>A for loop can only be supplied to <code>print</code> in the form of a comprehension.</p>

<p>But, if the list contents are in the respective order you require you can simply do:</p>

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

<p>This just matches each bracket with each item in the list. If you need to order this differently you just supply their relative position:</p>

<pre><code>print("The winners of {1} were: {0} with a score of {2}".format(*winners))
</code></pre>

python python-3.x