Toby Dickenson wrote: > The ?? operator first evaluated its left operand. If that succeeds its value > is returned. If that raised an exception it evaluates and returns its right > operand. That allowed your example to be written: > > value = a[key] ?? b[key] ?? 0
That wouldn't make sense so much in Python, because you don't usually want to catch all exceptions, only particular ones. So the operator would need to be parameterised somehow with the exception to catch, which would make it much less concise. A more Pythonic way would be something like value = a.get(key) or b.get(key) or 0 If some of your legitimate values can be false, you might need to use functions that attempt to get a value and return it wrapped somehow. The thought has just occurred that what *might* be useful here is an operator that works like "or", except that the only value it recognises as "false" is None. Not sure what to call it, though... -- Greg _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
