What is this kind of chain assignment and comparison in python?
<p>(Python 2.7 question)</p>

<p>I found a pattern similar to the following in a python codebase:</p>

<pre><code>&gt;&gt;&gt; a = b == 7
&gt;&gt;&gt; a
True
&gt;&gt;&gt; b
7
&gt;&gt;&gt; a = b == -7
&gt;&gt;&gt; a
False
&gt;&gt;&gt; b
7
</code></pre>

<p>I'm looking for the terminology for this - I found some other answers that referred to (a = b = 7) as "chain assignment". What is the format (a = b == 7) called?</p>

<p>This is just a normal assignment statement.  If you are ever curious about how a line of python is parsed, try the <code>ast</code> module:</p>

<pre><code>&gt;&gt;&gt; import ast
&gt;&gt;&gt; ast.dump(ast.parse('a = b == 7'), annotate_fields=False)
"Module([Assign([Name('a', Store())], Compare(Name('b', Load()), [Eq()], [Num(7)]))])"
</code></pre>

<p>We can see that there is an equality comparison with <code>b</code> and <code>7</code>, and that result is used in an assignment to <code>a</code>.  </p>

python python-2.7