3 ms·
The new assignment expression is great and I wish that an optional operator (`?`) and Elvis operator (`?:`) will make it to Python one day, too. I would love to
by blumomo 7y ago
The new assignment expression is great and I wish that an optional operator (`?`) and Elvis operator (`?:`) will make it to Python one day, too. I would love to write:
v = obj?.prop1?.prop2 ?: "default"
instead of long if conditions:
v = obj.prop1.prop2 if obj and obj.prop1 and obj.prop1.prop2 else "default"
A PEP for Python 3.8 existed but has been deferred: https://www.python.org/dev/peps/pep-0505/ https://www.python.org/dev/peps/pep-0505/