Is there a Python equivalent to the C# ?. and ?? operators?
<p>For instance, in C# (starting with v6) I can say:</p>

<pre><code>mass = (vehicle?.Mass / 10) ?? 150;
</code></pre>

<p>to set mass to a tenth of the vehicle's mass if there is a vehicle, but 150 if the vehicle is null (or has a null mass, if the Mass property is of a nullable type).</p>

<p>Is there an equivalent construction in Python (specifically IronPython) that I can use in scripts for my C# app?</p>

<p>This would be particularly useful for displaying defaults for values that can be modified by other values - for instance, I might have an armor component defined in script for my starship that is always consumes 10% of the space available on the ship it's installed on, and its other attributes scale as well, but I want to display defaults for the armor's size, hitpoints, cost, etc. so you can compare it with other ship components. Otherwise I might have to write a convoluted expression that does a null check or two, like I had to in C# before v6.</p>

<p>No, Python does not (yet) have NULL-coalescing operators. </p>

<p>There is a <em>proposal</em> (<a href="https://www.python.org/dev/peps/pep-0505/">PEP 505 â <em>None-aware operators</em></a>) to add such operators, but no consensus exists wether or not these should be added to the language at all and if so, what form these would take.</p>

<p>From the <em>Implementation</em> section:</p>

<blockquote>
  <p>Given that the need for None -aware operators is questionable and the spelling of said operators is almost incendiary, the implementation details for CPython will be deferred unless and until we have a clearer idea that one (or more) of the proposed operators will be approved.</p>
</blockquote>

<p>Note that Python doesn't really <em>have</em> a concept of <code>null</code>. Python names and attributes <em>always</em> reference <em>something</em>, they are never a <code>null</code> reference. <code>None</code> is just another object in Python, and the community is reluctant to make that one object so special as to need its own operators.</p>

<p>Until such time this gets implemented (if ever, and IronPython catches up to that Python release), you can use Python's <a href="https://docs.python.org/3/reference/expressions.html#conditional-expressions">conditional expression</a> to achieve the same:</p>

<pre><code>mass = 150 if vehicle is None or vehicle.Mass is None else vehicle.Mass / 10
</code></pre>

python ironpython