Loops/For with a specified step: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Removed "One liner" by Shadowys as the task is to use a for loop..)
Line 872: Line 872:
print "%d," % i,
print "%d," % i,
print "who do we appreciate?"</lang>
print "who do we appreciate?"</lang>

{{works with|Python|3.x}}
{{works with|Python|3.x}}
<lang python>for i in range(2, 9, 2):
<lang python>for i in range(2, 9, 2):
print("%d, " % i, end="")
print("%d, " % i, end="")
print("who do we appreciate?")</lang>
print("who do we appreciate?")</lang>

One liner:
{{out}}
<lang python>
print("%s, who do we appreciate"%(", ".join(map(str,range(2,9,2)))))
</lang>
Output
<pre>2, 4, 6, 8, who do we appreciate?</pre>
<pre>2, 4, 6, 8, who do we appreciate?</pre>