Python using while loop with a list name
<p>I am a beginner to python so this might be easy but I am not sure of what the following code means.</p>

<pre><code>q=[start]
    while q:
</code></pre>

<p>Does this mean when there is at least one element in the list q execute it and q becomes false when it is empty?
Edit:I cannot execute it at the moment and I need to find it quickly.</p>

<p>The line <code>q = [start]</code> means <em>create a variable called <code>q</code>, and assign the value <code>[start]</code> to it</em>. In this case, it will create a list with one element: the value of the variable <code>start</code>. It's the exact same syntax as <code>q = [1, 2]</code>, but it uses a variable instead of a constant value.</p>

<p>After this, the line <code>while q:</code> is a use (or abuse) of Python's type conversion system. While loops require a boolean condition to know whether they should repeat, so your code is equivalent to <code>while bool(q):</code>. To understand how this works, let's examine the possible cases:</p>

<pre><code>bool([1]) == True # This applies for any non-empty list
bool([]) == False # This applies to any empty list
</code></pre>

<p>Therefore, the meaning of <code>while q:</code> is actually 'while <code>q</code> is non-empty'.</p>

python list while-loop