Python: Probably More than 90% of Coders are Missing This Easy Trick
<p>If you are already familiar with <strong>online interviews</strong> and <strong>coding practice websites</strong>, you would for sure, love this easy Python feature.</p>
<p>Read this completely for a better understanding!</p>
<p>For example, I ask you to <strong>print a list of values</strong>. You would do that using a <code>for</code> loop in no time.</p>
<pre>
li = [10, 20, 30, 40, 50]
for i in li:
print(i)</pre>
<pre>
Output:
10
20
30
40
50</pre>
<p>But now, I ask if you can <strong>print the values in the same line with a space between each element</strong>. You would still make that look easy by using the <strong>end argument</strong> within <code>print()</code>.</p>
<pre>
li = [10, 20, 30, 40, 50]
for i in li:
print(i, end=' ')</pre>
<pre>
Output:
10 20 30 40 50 </pre>
<h2>The Problem</h2>
<p>Now, here is the exact problem. The output when seen looks like what I asked for. But when you select the output, an <strong>annoying space pops out</strong> of nowhere.</p>
<p>And that is because the last loop prints 50 and then adds a space after it with the use of the <strong>end argument</strong>. Though the end argument helped us in printing space in between, this side effect of putting a white space at the last is not what we wanted.</p>
<p>Especially, when it comes to online interview questions and coding platforms, they expect us to <strong>get the exact output as given</strong>. Even an extra space would result in the website not accepting our solution.</p>
<p><a href="https://python.plainenglish.io/python-probably-more-than-90-of-coders-are-missing-this-easy-trick-1f5e1c2d8561">Click Here</a></p>