title: Optional chaining in Python
body: <p>In JavaScript, if I'm not sure whether every element of the chain exists/is not undefined, I can do <code>foo?.bar</code>, and if <code>bar</code> does not exist on <code>foo</code>, the interpreter will silently short circuit it and not throw an error.</p>
  <p>Is there anything similar in Python? For now, I've been doing it like this:</p>
  <pre class="lang-py prettyprint-override"><code>if foo and foo.bar and foo.bar.baz:
      # do something
  </code></pre>
  <p>My intuition tells me that this isn't the best way to check whether every element of the chain exists. Is there a more elegant/Pythonic way to do this?</p>