For example, in C # (starting with v6) I can say:
mass = (vehicle?.Mass / 10) ?? 150;
to set the mass to a tenth of the mass of the vehicle if there is a vehicle, but 150 if the vehicle has a zero value (or has zero mass if the Mass property is of type with a zero value).
Is there an equivalent construct in Python (specifically IronPython) that I can use in scripts for my C # application?
This would be especially useful for displaying default values ββfor values ββthat can be changed by other values ββ- for example, I can have an armored component defined in a script for my starship that always consumes 10% of the space available on put it on and others its attributes, but I want to display the default values ββfor armor size, hitpoints, cost, etc., so that you can compare it with other components of the ship. Otherwise, I may have to write a convoluted expression that does a null check or two, as I should have in C # before v6.
python ironpython
ekolis
source share