What's Python equivalent to or equals expression, to get return foo or foo = 'bar' working?
<p>I'd like to do something like:</p>

<pre><code>def get_foo():   
  return self._foo or self._foo = Bar()
</code></pre>

<p>I am looking for the cleanest way to do it. Is it possible with or equals? </p>

<p>My attempts failed:</p>

<pre><code>&gt;&gt;&gt; foo = None
&gt;&gt;&gt; foo or 'bar'
'bar'
&gt;&gt;&gt; foo
&gt;&gt;&gt; foo or foo = 'bar'
  File "&lt;stdin&gt;", line 1
SyntaxError: can't assign to operator
&gt;&gt;&gt; foo or (foo = 'bar')
  File "&lt;stdin&gt;", line 1
    foo or (foo = 'bar')
                ^
SyntaxError: invalid syntax
</code></pre>
