Null coalescing operator
9 Sep
2016
9 Sep
'16
8:01 p.m.
Sometimes I find myself in need of this nice operator that I used back in the days when I was programming in .NET, essentially an expression
expr ?? instead
should return expr when it `is not None` and `instead` otherwise. A piece of code that I just wrote, you can see a use case: def _sizeof(self, context): if self.totalsizeof is not None: return self.totalsizeof else: raise SizeofError("cannot calculate size") With the oprator it would just be def _sizeof(self, context): return self.totalsizeof ?? raise SizeofError("cannot calculate size") pozdrawiam, Arkadiusz Bulski
2701
Age (days ago)
2758
Last active (days ago)
123 comments
36 participants
participants (36)
-
Alexander Belopolsky
-
Alexandre Brault
-
Arek Bulski
-
Barry Warsaw
-
Brett Cannon
-
Chris Angelico
-
Chris Barker
-
David Mertz
-
Eric Snow
-
Ethan Furman
-
Greg Ewing
-
Guido van Rossum
-
Guido van Rossum
-
Gustavo Carneiro
-
Ivan Levkivskyi
-
Joonas Liik
-
Kyle Lahnakoski
-
Mark E. Haase
-
Matt Gilson
-
Matthias Bussonnier
-
Mikhail V
-
MRAB
-
Nick Badger
-
Nick Coghlan
-
Nikolaus Rath
-
Paul Moore
-
Pavol Lisy
-
Ralph Broenink
-
Random832
-
Ryan Gonzalez
-
Stephen J. Turnbull
-
Steven D'Aprano
-
Sven R. Kunze
-
tritium-list@sdamon.com
-
Zachary Ware
-
Zero Piraeus