Python version of JS's x = variable || DEFAULT_VARIABLE?
<p>I'm finding myself using hasattr a lot and would like to write more concisely.</p>

<p>In JS, I use the following pattern often:</p>

<pre><code>var x = variable || DEFAULT_VARIABLE;
</code></pre>

<p>What's the equivalent in Python?</p>

<p>Something better than this...</p>

<pre><code>if hasattr(my_obj, 'my_key'):
  x = my_obj.my_key
else:
  x = 3
</code></pre>

<p>EDIT: Fixed a bug mixing up objects and dicts.</p>
