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>Omit the second <code>return</code>. To simplify:</p>

<pre><code>&gt;&gt;&gt; def foo(x):
...    return True if x == 2 else False
</code></pre>

<p>read it as  "return the results of this ternary expression" not "return this thing in one case but return some other thing in another case"</p>

python if-statement