While statement and expressions
<p><code>while</code> loop statement gets executed as long as the expression is true. </p>

<p>After the 10th time, the pop() throws an IndexError back because there are 10 elements in the list. But, the below code executes fine without any error. Why is it so?</p>

<pre><code>a = [x*x for x in range(10)]
while a.pop():
    print("elements in the list")
</code></pre>

<p>It might be a very basic question, but I am trying to get comfortable with Python.</p>

<blockquote>
  <p>After the 10th time, the pop() throws an IndexError back because there are 10 elements in the list.</p>
</blockquote>

<p>No, the code never tries to do any <code>pop</code>s after the 10th, because the 10th <code>pop</code> returns <code>0</code>. <code>0</code> is considered false in a boolean context, so the loop terminates at that point.</p>

python while-loop