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>First note, in Python 3 <code>print</code> is a function, but it was a statement in Python 2. Also you can't use a <code>for</code> statement as an argument. 
Only such weird solution comes to my mind, which only looks like a for loop:</p>

<pre><code>data = ['Hockey','Swiss', '3']
print("Sport is {}, winner is {}, score is {}".format(*( _ for _ in data )))
</code></pre>

<p>Of course, because <code>print</code> is a function, you can write your own function with all stuff you need, as an example:</p>

<pre><code>def my_print(pattern, *data):
    print(pattern.format(*( _ for _ in data)))  

my_print("Sport is {}, winner is {}, score is {}", 'Hockey', 'Swiss', '3')
</code></pre>

<p>You can also read about <strong>f-strings</strong> <a href="https://www.python.org/dev/peps/pep-0498/" rel="nofollow">"Literal String Interpolation" PEP 498</a>, which will be introduced in Python 3.6. This f-strings will provide a way to embed expressions inside string literals, using a minimal syntax.</p>

python python-3.x