SyntaxError: invalid syntax -- One line if statement in python
<p>My initial <code>if else</code> code is :</p>

<pre><code>if response.get('fulfillments') is None:
    return (False, response)
else:
    return (True, response)
</code></pre>

<p>But I want to convert it to <code>one-line-if-else-statement</code>. </p>

<p>Here is what I am doing : </p>

<pre><code>return (False, response) if response.get('fulfillments') is None else return (True, response)
</code></pre>

<p>But it is raising a syntax error, What am I doing wrong ?</p>

<p>A one-line <code>if-else</code> is not the same as the block.  It is an expression, not a statement or multiple statements.  You can't do something like:</p>

<pre><code>(x = 4) if x &gt; 5 else (x = 6)
</code></pre>

<p>Because those are statements.  Instead, it is like this:</p>

<pre><code>x = (4 if x &gt; 5 else 6)
</code></pre>

<p>Or in your case:</p>

<pre><code>return (False, response) if response.get('fulfillments') is None else (True, response)
</code></pre>

<p>You don't really need the <code>if-else</code>, though.  Just do this:</p>

<pre><code>return (response.get('fulfillments') is not None, response)
</code></pre>

python if-statement